the-tcpdump-group / tcpdump

the TCPdump network dissector
https://www.tcpdump.org/
Other
2.71k stars 848 forks source link

UndefinedBehaviorSanitizer: undefined-behavior print-zep.c:86 #742

Open fxlb opened 5 years ago

fxlb commented 5 years ago

At line 86: https://github.com/the-tcpdump-group/tcpdump/blob/400643120a48eca33973f6a47b34f0dcfde4d20a/print-zep.c#L86

print-zep.c:86:22: runtime error: unsigned integer overflow: 16843009 - 2208988800 cannot be represented in type 'unsigned int'

POC: pkt-64-zep.c-86.pcap.gz

cc: @kivinen

kivinen commented 5 years ago

fxlb writes:

At line 86: https://github.com/the-tcpdump-group/tcpdump/blob/400643120a48eca33973f6a47b34f0dcfde4d20a/print-zep.c#L86

print-zep.c:86:22: runtime error: unsigned integer overflow: 16843009 - 2208988800 cannot be represented in type 'unsigned int'

POC: pkt-64-zep.c-86.pcap.gz

The print-ntp.c:p_ntp_time seems to have some changes compared to the print-zep.c:zep_print_ts. Both of them do the same, i.e., print ntp time stamp.

It might be good idea to take rest of the changes from that function to here too. This line seems to be solved by using int64_t first and then copying it to time_t. On the other hand, I think you will still get same warning as seconds_64bit will be negative in that case and it still will not fit the time_t... If you try same time for print-ntp.c:p_ntp_time do you get same errors.

If course we could simply change the

if (i) {

to

if (i >= JAN_1970) {

and ignore printing time if it is before 1970. That change would most likely be good for print-ntp.c:p_ntp_time too. -- kivinen@iki.fi