fixed signed integer overflow in asc2log.c:100
Issue:
echo "0.0000 0 Rx d 8 8D 00 10 01 00 82 01 00
0.200000000000000000 0- 0000 Rx d 8 8D 00 10 01 00 82 01 00" |
./asc2log
can-utils/asc2log.c💯20: runtime error: signed integer overflow:
200000000000000000 * 100 cannot be represented in type 'long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior asc2log.c💯20
pull/321/head
parent
2b0ef5c330
commit
34732eddeb
16
asc2log.c
16
asc2log.c
|
|
@ -50,6 +50,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/error.h>
|
||||
|
|
@ -206,6 +207,13 @@ void eval_can(char* buf, struct timeval *date_tvp, char timestamps, char base, i
|
|||
if (strlen(dir) != 2) /* "Rx" or "Tx" */
|
||||
return;
|
||||
|
||||
/* check for signed integer overflow */
|
||||
if (dplace == 4 && read_tv.tv_usec >= INT_MAX / 100)
|
||||
return;
|
||||
|
||||
if (dplace == 5 && read_tv.tv_usec >= INT_MAX / 10)
|
||||
return;
|
||||
|
||||
if (dir[0] == 'R')
|
||||
extra_info = " R\n";
|
||||
else
|
||||
|
|
@ -269,6 +277,14 @@ void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps, int dplace
|
|||
if (strlen(dir) != 2) /* "Rx" or "Tx" */
|
||||
return;
|
||||
|
||||
/* check for signed integer overflow */
|
||||
if (dplace == 4 && read_tv.tv_usec >= INT_MAX / 100)
|
||||
return;
|
||||
|
||||
/* check for signed integer overflow */
|
||||
if (dplace == 5 && read_tv.tv_usec >= INT_MAX / 10)
|
||||
return;
|
||||
|
||||
if (dir[0] == 'R')
|
||||
extra_info = " R\n";
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in New Issue