From 83f4d9d5596b54bf2e7fbc540e71b3464542374a Mon Sep 17 00:00:00 2001 From: Kirill Isakov Date: Tue, 17 Aug 2021 16:35:22 +0600 Subject: [PATCH] Fix UBSAN warnings in linux/device.c. linux/device.c:149:11: runtime error: implicit conversion from type 'ssize_t' (aka 'long') of value -1 (64-bit, signed) to type 'size_t' (aka 'unsigned long') changed the value to 18446744073709551615 (64-bit, unsigned) #0 0x55e3cb851f84 in read_packet /home/runner/work/tinc/tinc/src/linux/device.c:149:11 #1 0x55e3cb7bb7fe in handle_device_data /home/runner/work/tinc/tinc/src/net_packet.c:1906:5 #2 0x55e3cb78e6e0 in event_loop /home/runner/work/tinc/tinc/src/event.c:353:5 #3 0x55e3cb7a6a90 in main_loop /home/runner/work/tinc/tinc/src/net.c:505:6 #4 0x55e3cb83d241 in main /home/runner/work/tinc/tinc/src/tincd.c:614:11 #5 0x7fec881950b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) #6 0x55e3cb757dcd in _start (/home/runner/work/tinc/tinc/src/tincd+0x9adcd) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/device.c:149:11 in linux/device.c:163:23: runtime error: unsigned integer overflow: 18446744073709551615 + 10 cannot be represented in type 'unsigned long' #0 0x55e3cb852253 in read_packet /home/runner/work/tinc/tinc/src/linux/device.c:163:23 #1 0x55e3cb7bb7fe in handle_device_data /home/runner/work/tinc/tinc/src/net_packet.c:1906:5 #2 0x55e3cb78e6e0 in event_loop /home/runner/work/tinc/tinc/src/event.c:353:5 #3 0x55e3cb7a6a90 in main_loop /home/runner/work/tinc/tinc/src/net.c:505:6 #4 0x55e3cb83d241 in main /home/runner/work/tinc/tinc/src/tincd.c:614:11 #5 0x7fec881950b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) #6 0x55e3cb757dcd in _start (/home/runner/work/tinc/tinc/src/tincd+0x9adcd) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior linux/device.c:163:23 in --- src/linux/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linux/device.c b/src/linux/device.c index 8e239591..dfe75b6f 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -142,7 +142,7 @@ static void close_device(void) { } static bool read_packet(vpn_packet_t *packet) { - size_t inlen; + ssize_t inlen; switch(device_type) { case DEVICE_TYPE_TUN: -- 2.20.1