From 79601bd1d40110f0cfde90730fdb43dd4e2eb838 Mon Sep 17 00:00:00 2001 From: Oliver Hartkopp Date: Thu, 10 Aug 2023 10:31:26 +0200 Subject: [PATCH] canplayer: ensure 6 decimal places in timestamp for first frame The check has only been applied after the first CAN frame has been read and evaluated. This lead to an unintended sending of a single handcrafted frame with a following (intended) failure at the second frame. Apply the check also for the very first CAN frame that is processed. Fixes: ee0233505bf6 ("canplayer: ensure 6 decimal places in timestamp") Signed-off-by: Oliver Hartkopp --- canplayer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/canplayer.c b/canplayer.c index 51adc77..3d053d2 100644 --- a/canplayer.c +++ b/canplayer.c @@ -425,6 +425,15 @@ int main(int argc, char **argv) return 1; } + /* + * ensure the fractions of seconds are 6 decimal places long to catch + * 3rd party or handcrafted logfiles that treat the timestamp as float + */ + if (strchr(buf, ')') - strchr(buf, '.') != 7) { + fprintf(stderr, "timestamp format in logfile requires 6 decimal places\n"); + return 1; + } + if (use_timestamps) { /* throttle sending due to logfile timestamps */ gettimeofday(&today_tv, NULL);