fix timeval to ASCII unsigned value conversion

As reported by Oleksij Rempel here
https://github.com/linux-can/can-utils/issues/233#issuecomment-674818935
the representation of timeval timestamps are signed values which leads to
negative values on 32 bit machines addressing the year 2038 unix sec counter
overflow.

Fix the issue on 32 bit systems by converting the timeval values to unsigned
ASCII value representations.

Fixes: https://github.com/linux-can/can-utils/issues/234
Reported-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2020-08-18 12:51:35 +02:00
parent ab23c6f7e7
commit a4905ed7c8
8 changed files with 28 additions and 28 deletions
+2 -2
View File
@@ -395,7 +395,7 @@ int main(int argc, char **argv)
eof = 0;
if (sscanf(buf, "(%ld.%ld) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;
@@ -474,7 +474,7 @@ int main(int argc, char **argv)
break;
}
if (sscanf(buf, "(%ld.%ld) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
if (sscanf(buf, "(%lu.%lu) %s %s", &log_tv.tv_sec, &log_tv.tv_usec,
device, ascframe) != 4) {
fprintf(stderr, "incorrect line format in logfile\n");
return 1;