]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Fix '-tt' option printing when time > 2106-02-07T06:28:15Z
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 27 Sep 2024 18:05:22 +0000 (20:05 +0200)
committerfxlb <[email protected]>
Sat, 28 Sep 2024 14:01:32 +0000 (14:01 +0000)
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).

tests/time.tests
tests/time_2106_overflow-tt.out [new file with mode: 0644]
tests/time_2107-tt.out [new file with mode: 0644]
util-print.c

index d2634efd633c970c0eaec5529d871983df92c7da..d8190630c1e96d733b2c8fcfc54ff8be5c943868 100644 (file)
@@ -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 (file)
index 0000000..2b66ff8
--- /dev/null
@@ -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 (file)
index 0000000..6ac5518
--- /dev/null
@@ -0,0 +1 @@
+    1  4323283200.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56
index 71674221d1dca55a422c7865e12dcb7fd5f8328e..47823aec2a65461605a831ea21b457529e754fab 100644 (file)
@@ -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);
 }