Skip to content

Commit ad5e31b

Browse files
committed
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).
1 parent a41457a commit ad5e31b

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

tests/time.tests

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ $testlist = [
6363
output => 'time_2107.out',
6464
args => '-q'
6565
},
66+
{
67+
config_set => 'HAVE_TIME_T_64',
68+
name => 'time_2106_overflow-tt',
69+
input => 'time_2106_overflow.pcapng',
70+
output => 'time_2106_overflow-tt.out',
71+
args => '-tt -q SPECIAL_t'
72+
},
73+
{
74+
config_set => 'HAVE_TIME_T_64',
75+
name => 'time_2107-tt',
76+
input => 'time_2107.pcapng',
77+
output => 'time_2107-tt.out',
78+
args => '-tt -q SPECIAL_t'
79+
},
6680
];
6781

6882
1;

tests/time_2106_overflow-tt.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 4294967296.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56

tests/time_2107-tt.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 4323283200.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56

util-print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ ts_unix_print(netdissect_options *ndo, const struct timeval *tv)
293293
return;
294294
}
295295

296-
ND_PRINT("%u", (unsigned)tv->tv_sec);
296+
ND_PRINT("%" PRId64, (int64_t)tv->tv_sec);
297297
ts_frac_print(ndo, tv);
298298
}
299299

0 commit comments

Comments
 (0)