From: Francois-Xavier Le Bail Date: Fri, 27 Sep 2024 18:05:22 +0000 (+0200) Subject: Fix '-tt' option printing when time > 2106-02-07T06:28:15Z X-Git-Url: https://git.tcpdump.org/tcpdump/commitdiff_plain/ad5e31b10c83431845292be5ca4bfa0f284840fd Fix '-tt' option printing when time > 2106-02-07T06:28:15Z Currently the printing with '-tt' option (unix time) is incorrect. Some examples: 1) test: time_2106_overflow-tt 0.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 Should be: 4294967296.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 2) test: time_2107-tt 28315904.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 Should be: 4323283200.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 Two build examples: 64-bit build: tv->tv_sec has type '__time_t' (aka 'long'). 32-bit build with _TIME_BITS=64: tv->tv_sec has type '__time64_t' (aka 'long long'). Using 'unsigned' cast is incorrect for these 64-bit data. Thus convert to 'int64_t' and print with '"%" PRId64'. Add two test cases (existing pcapng printed with -tt). --- diff --git a/tests/time.tests b/tests/time.tests index d2634efd..d8190630 100644 --- a/tests/time.tests +++ b/tests/time.tests @@ -63,6 +63,20 @@ $testlist = [ output => 'time_2107.out', args => '-q' }, + { + config_set => 'HAVE_TIME_T_64', + name => 'time_2106_overflow-tt', + input => 'time_2106_overflow.pcapng', + output => 'time_2106_overflow-tt.out', + args => '-tt -q SPECIAL_t' + }, + { + config_set => 'HAVE_TIME_T_64', + name => 'time_2107-tt', + input => 'time_2107.pcapng', + output => 'time_2107-tt.out', + args => '-tt -q SPECIAL_t' + }, ]; 1; diff --git a/tests/time_2106_overflow-tt.out b/tests/time_2106_overflow-tt.out new file mode 100644 index 00000000..2b66ff8d --- /dev/null +++ b/tests/time_2106_overflow-tt.out @@ -0,0 +1 @@ + 1 4294967296.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 diff --git a/tests/time_2107-tt.out b/tests/time_2107-tt.out new file mode 100644 index 00000000..6ac55187 --- /dev/null +++ b/tests/time_2107-tt.out @@ -0,0 +1 @@ + 1 4323283200.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56 diff --git a/util-print.c b/util-print.c index 71674221..47823aec 100644 --- a/util-print.c +++ b/util-print.c @@ -293,7 +293,7 @@ ts_unix_print(netdissect_options *ndo, const struct timeval *tv) return; } - ND_PRINT("%u", (unsigned)tv->tv_sec); + ND_PRINT("%" PRId64, (int64_t)tv->tv_sec); ts_frac_print(ndo, tv); }