From 34732eddeb7a4bcf2f748d7a94eb6a806f370e88 Mon Sep 17 00:00:00 2001 From: weichslgartner Date: Mon, 13 Jun 2022 15:51:31 +0200 Subject: [PATCH] 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:100:20: runtime error: signed integer overflow: 200000000000000000 * 100 cannot be represented in type 'long' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior asc2log.c:100:20 --- asc2log.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/asc2log.c b/asc2log.c index 7f932ef..ea6b486 100644 --- a/asc2log.c +++ b/asc2log.c @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -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