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>pull/238/head
parent
ab23c6f7e7
commit
a4905ed7c8
18
asc2log.c
18
asc2log.c
|
|
@ -72,7 +72,7 @@ void print_usage(char *prg)
|
||||||
|
|
||||||
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen) {
|
void prframe(FILE *file, struct timeval *tv, int dev, struct canfd_frame *cf, unsigned int max_dlen) {
|
||||||
|
|
||||||
fprintf(file, "(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
|
fprintf(file, "(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
|
||||||
|
|
||||||
if (dev > 0)
|
if (dev > 0)
|
||||||
fprintf(file, "can%d ", dev-1);
|
fprintf(file, "can%d ", dev-1);
|
||||||
|
|
@ -143,7 +143,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
|
|
||||||
if (base == 'h') { /* check for CAN frames with hexadecimal values */
|
if (base == 'h') { /* check for CAN frames with hexadecimal values */
|
||||||
|
|
||||||
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %x %x %x %x %x %x %x %x",
|
items = sscanf(buf, "%lu.%lu %d %s %*s %c %d %x %x %x %x %x %x %x %x",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, &rtr, &dlc,
|
tmp1, &rtr, &dlc,
|
||||||
&data[0], &data[1], &data[2], &data[3],
|
&data[0], &data[1], &data[2], &data[3],
|
||||||
|
|
@ -158,7 +158,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
|
|
||||||
} else { /* check for CAN frames with decimal values */
|
} else { /* check for CAN frames with decimal values */
|
||||||
|
|
||||||
items = sscanf(buf, "%ld.%ld %d %s %*s %c %d %d %d %d %d %d %d %d %d",
|
items = sscanf(buf, "%lu.%lu %d %s %*s %c %d %d %d %d %d %d %d %d %d",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, &rtr, &dlc,
|
tmp1, &rtr, &dlc,
|
||||||
&data[0], &data[1], &data[2], &data[3],
|
&data[0], &data[1], &data[2], &data[3],
|
||||||
|
|
@ -191,7 +191,7 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for ErrorFrames */
|
/* check for ErrorFrames */
|
||||||
if (sscanf(buf, "%ld.%ld %d %s",
|
if (sscanf(buf, "%lu.%lu %d %s",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec,
|
&read_tv.tv_sec, &read_tv.tv_usec,
|
||||||
&interface, tmp1) == 4) {
|
&interface, tmp1) == 4) {
|
||||||
|
|
||||||
|
|
@ -232,12 +232,12 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
|
||||||
memset(&cf, 0, sizeof(cf));
|
memset(&cf, 0, sizeof(cf));
|
||||||
|
|
||||||
/* check for valid line without symbolic name */
|
/* check for valid line without symbolic name */
|
||||||
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %hhx %hhx %x %d ",
|
if (sscanf(buf, "%lu.%lu %*s %d %*s %s %hhx %hhx %x %d ",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
|
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
|
||||||
|
|
||||||
/* check for valid line with a symbolic name */
|
/* check for valid line with a symbolic name */
|
||||||
if (sscanf(buf, "%ld.%ld %*s %d %*s %s %*s %hhx %hhx %x %d ",
|
if (sscanf(buf, "%lu.%lu %*s %d %*s %s %*s %hhx %hhx %x %d ",
|
||||||
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
&read_tv.tv_sec, &read_tv.tv_usec, &interface,
|
||||||
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
|
tmp1, &brs, &esi, &dlc, &dlen) != 8) {
|
||||||
|
|
||||||
|
|
@ -460,12 +460,12 @@ int main(int argc, char **argv)
|
||||||
gettimeofday(&date_tv, NULL);
|
gettimeofday(&date_tv, NULL);
|
||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("date %ld => %s", date_tv.tv_sec, ctime(&date_tv.tv_sec));
|
printf("date %lu => %s", date_tv.tv_sec, ctime(&date_tv.tv_sec));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for decimal places length in valid CAN frames */
|
/* check for decimal places length in valid CAN frames */
|
||||||
if (sscanf(buf, "%ld.%s %s ", &tmp_tv.tv_sec, tmp2, tmp1) == 3){
|
if (sscanf(buf, "%lu.%s %s ", &tmp_tv.tv_sec, tmp2, tmp1) == 3){
|
||||||
dplace = strlen(tmp2);
|
dplace = strlen(tmp2);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("decimal place %d, e.g. '%s'\n", dplace, tmp2);
|
printf("decimal place %d, e.g. '%s'\n", dplace, tmp2);
|
||||||
|
|
@ -481,7 +481,7 @@ int main(int argc, char **argv)
|
||||||
/* so try to get CAN frames and ErrorFrames and convert them */
|
/* so try to get CAN frames and ErrorFrames and convert them */
|
||||||
|
|
||||||
/* check classic CAN format or the CANFD tag which can take both types */
|
/* check classic CAN format or the CANFD tag which can take both types */
|
||||||
if (sscanf(buf, "%ld.%ld %s ", &tmp_tv.tv_sec, &tmp_tv.tv_usec, tmp1) == 3){
|
if (sscanf(buf, "%lu.%lu %s ", &tmp_tv.tv_sec, &tmp_tv.tv_usec, tmp1) == 3){
|
||||||
if (!strncmp(tmp1, "CANFD", 5))
|
if (!strncmp(tmp1, "CANFD", 5))
|
||||||
eval_canfd(buf, &date_tv, timestamps, dplace, outfile);
|
eval_canfd(buf, &date_tv, timestamps, dplace, outfile);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
10
candump.c
10
candump.c
|
|
@ -706,7 +706,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* log CAN frame with absolute timestamp & device */
|
/* log CAN frame with absolute timestamp & device */
|
||||||
sprint_canframe(buf, &frame, 0, maxdlen);
|
sprint_canframe(buf, &frame, 0, maxdlen);
|
||||||
fprintf(logfile, "(%010ld.%06ld) %*s %s\n",
|
fprintf(logfile, "(%010lu.%06lu) %*s %s\n",
|
||||||
tv.tv_sec, tv.tv_usec,
|
tv.tv_sec, tv.tv_usec,
|
||||||
max_devname_len, devname[idx], buf);
|
max_devname_len, devname[idx], buf);
|
||||||
}
|
}
|
||||||
|
|
@ -716,7 +716,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* print CAN frame in log file style to stdout */
|
/* print CAN frame in log file style to stdout */
|
||||||
sprint_canframe(buf, &frame, 0, maxdlen);
|
sprint_canframe(buf, &frame, 0, maxdlen);
|
||||||
printf("(%010ld.%06ld) %*s %s\n",
|
printf("(%010lu.%06lu) %*s %s\n",
|
||||||
tv.tv_sec, tv.tv_usec,
|
tv.tv_sec, tv.tv_usec,
|
||||||
max_devname_len, devname[idx], buf);
|
max_devname_len, devname[idx], buf);
|
||||||
goto out_fflush; /* no other output to stdout */
|
goto out_fflush; /* no other output to stdout */
|
||||||
|
|
@ -735,7 +735,7 @@ int main(int argc, char **argv)
|
||||||
switch (timestamp) {
|
switch (timestamp) {
|
||||||
|
|
||||||
case 'a': /* absolute with timestamp */
|
case 'a': /* absolute with timestamp */
|
||||||
printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
printf("(%010lu.%06lu) ", tv.tv_sec, tv.tv_usec);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A': /* absolute with date */
|
case 'A': /* absolute with date */
|
||||||
|
|
@ -745,7 +745,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
tm = *localtime(&tv.tv_sec);
|
tm = *localtime(&tv.tv_sec);
|
||||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
printf("(%s.%06ld) ", timestring, tv.tv_usec);
|
printf("(%s.%06lu) ", timestring, tv.tv_usec);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -762,7 +762,7 @@ int main(int argc, char **argv)
|
||||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||||
if (diff.tv_sec < 0)
|
if (diff.tv_sec < 0)
|
||||||
diff.tv_sec = diff.tv_usec = 0;
|
diff.tv_sec = diff.tv_usec = 0;
|
||||||
printf("(%03ld.%06ld) ", diff.tv_sec, diff.tv_usec);
|
printf("(%03lu.%06lu) ", diff.tv_sec, diff.tv_usec);
|
||||||
|
|
||||||
if (timestamp == 'd')
|
if (timestamp == 'd')
|
||||||
last_tv = tv; /* update for delta calculation */
|
last_tv = tv; /* update for delta calculation */
|
||||||
|
|
|
||||||
|
|
@ -410,7 +410,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
idx = idx2dindex(addr.can_ifindex, s[i]);
|
idx = idx2dindex(addr.can_ifindex, s[i]);
|
||||||
|
|
||||||
sprintf(temp, "(%ld.%06ld) %*s ",
|
sprintf(temp, "(%lu.%06lu) %*s ",
|
||||||
tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]);
|
tv.tv_sec, tv.tv_usec, max_devname_len, devname[idx]);
|
||||||
sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen);
|
sprint_canframe(temp+strlen(temp), &frame, 0, maxdlen);
|
||||||
strcat(temp, "\n");
|
strcat(temp, "\n");
|
||||||
|
|
@ -422,7 +422,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* print CAN frame in log file style to stdout */
|
/* print CAN frame in log file style to stdout */
|
||||||
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
|
||||||
printf("%*s ", max_devname_len, devname[idx]);
|
printf("%*s ", max_devname_len, devname[idx]);
|
||||||
fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
|
fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -395,7 +395,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
eof = 0;
|
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) {
|
device, ascframe) != 4) {
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -474,7 +474,7 @@ int main(int argc, char **argv)
|
||||||
break;
|
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) {
|
device, ascframe) != 4) {
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ int main(int argc, char **argv)
|
||||||
switch (timestamp) {
|
switch (timestamp) {
|
||||||
|
|
||||||
case 'a': /* absolute with timestamp */
|
case 'a': /* absolute with timestamp */
|
||||||
printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec);
|
printf("(%lu.%06lu) ", tv.tv_sec, tv.tv_usec);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A': /* absolute with date */
|
case 'A': /* absolute with date */
|
||||||
|
|
@ -366,7 +366,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
tm = *localtime(&tv.tv_sec);
|
tm = *localtime(&tv.tv_sec);
|
||||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
printf("(%s.%06ld) ", timestring, tv.tv_usec);
|
printf("(%s.%06lu) ", timestring, tv.tv_usec);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -383,7 +383,7 @@ int main(int argc, char **argv)
|
||||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||||
if (diff.tv_sec < 0)
|
if (diff.tv_sec < 0)
|
||||||
diff.tv_sec = diff.tv_usec = 0;
|
diff.tv_sec = diff.tv_usec = 0;
|
||||||
printf("(%ld.%06ld) ", diff.tv_sec, diff.tv_usec);
|
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
|
||||||
|
|
||||||
if (timestamp == 'd')
|
if (timestamp == 'd')
|
||||||
last_tv = tv; /* update for delta calculation */
|
last_tv = tv; /* update for delta calculation */
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* check devisor to be not zero */
|
/* check devisor to be not zero */
|
||||||
if (diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000){
|
if (diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000){
|
||||||
printf("%ld.%06lds ", diff_tv.tv_sec, diff_tv.tv_usec);
|
printf("%lu.%06lus ", diff_tv.tv_sec, diff_tv.tv_usec);
|
||||||
printf("=> %lu byte/s", (fflen * 1000) /
|
printf("=> %lu byte/s", (fflen * 1000) /
|
||||||
(diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000));
|
(diff_tv.tv_sec * 1000 + diff_tv.tv_usec / 1000));
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
|
||||||
switch (timestamp) {
|
switch (timestamp) {
|
||||||
|
|
||||||
case 'a': /* absolute with timestamp */
|
case 'a': /* absolute with timestamp */
|
||||||
printf("(%ld.%06ld) ", tv->tv_sec, tv->tv_usec);
|
printf("(%lu.%06lu) ", tv->tv_sec, tv->tv_usec);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'A': /* absolute with date */
|
case 'A': /* absolute with date */
|
||||||
|
|
@ -111,7 +111,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
|
||||||
|
|
||||||
tm = *localtime(&tv->tv_sec);
|
tm = *localtime(&tv->tv_sec);
|
||||||
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(timestring, 24, "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
printf("(%s.%06ld) ", timestring, tv->tv_usec);
|
printf("(%s.%06lu) ", timestring, tv->tv_usec);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ void printbuf(unsigned char *buffer, int nbytes, int color, int timestamp,
|
||||||
diff.tv_sec--, diff.tv_usec += 1000000;
|
diff.tv_sec--, diff.tv_usec += 1000000;
|
||||||
if (diff.tv_sec < 0)
|
if (diff.tv_sec < 0)
|
||||||
diff.tv_sec = diff.tv_usec = 0;
|
diff.tv_sec = diff.tv_usec = 0;
|
||||||
printf("(%ld.%06ld) ", diff.tv_sec, diff.tv_usec);
|
printf("(%lu.%06lu) ", diff.tv_sec, diff.tv_usec);
|
||||||
|
|
||||||
if (timestamp == 'd')
|
if (timestamp == 'd')
|
||||||
*last_tv = *tv; /* update for delta calculation */
|
*last_tv = *tv; /* update for delta calculation */
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ int main(int argc, char **argv)
|
||||||
if (buf[0] != '(')
|
if (buf[0] != '(')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec,
|
if (sscanf(buf, "(%lu.%lu) %s %s", &tv.tv_sec, &tv.tv_usec,
|
||||||
device, ascframe) != 4) {
|
device, ascframe) != 4) {
|
||||||
fprintf(stderr, "incorrect line format in logfile\n");
|
fprintf(stderr, "incorrect line format in logfile\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -262,9 +262,9 @@ int main(int argc, char **argv)
|
||||||
tv.tv_sec = tv.tv_usec = 0;
|
tv.tv_sec = tv.tv_usec = 0;
|
||||||
|
|
||||||
if (d4)
|
if (d4)
|
||||||
fprintf(outfile, "%4ld.%04ld ", tv.tv_sec, tv.tv_usec/100);
|
fprintf(outfile, "%4lu.%04lu ", tv.tv_sec, tv.tv_usec/100);
|
||||||
else
|
else
|
||||||
fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec);
|
fprintf(outfile, "%4lu.%06lu ", tv.tv_sec, tv.tv_usec);
|
||||||
|
|
||||||
if ((mtu == CAN_MTU) && (fdfmt == 0))
|
if ((mtu == CAN_MTU) && (fdfmt == 0))
|
||||||
can_asc(&cf, devno, nortrdlc, outfile);
|
can_asc(&cf, devno, nortrdlc, outfile);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue