From 15502d3c972332823dd379a6f6649a95f785030b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 24 Oct 2014 20:56:41 +0100 Subject: [PATCH] getdata: fix buffer-overflows reported by address sanitizer These happen when input configuration or leases files are empty. ==12876==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61900000a480 at pc 0x000000487442 bp 0x7fffbc3e16b0 sp 0x7fffbc3e0e70 READ of size 1025 at 0x61900000a480 thread T0 #0 0x487441 in __interceptor_strlen (/home/src/dhcpd-pools/dhcpd-pools+0x487441) #1 0x4bbb10 in parse_leases /home/src/dhcpd-pools/src/getdata.c:112:35 #2 0x4bb337 in main /home/src/dhcpd-pools/src/dhcpd-pools.c:268:2 #3 0x7f51909bf03f in __libc_start_main (/usr/lib/libc.so.6+0x2003f) #4 0x4b9c0c in _start (/home/src/dhcpd-pools/dhcpd-pools+0x4b9c0c) 0x61900000a480 is located 0 bytes to the right of 1024-byte region [0x61900000a080,0x61900000a480) allocated by thread T0 here: #0 0x49c58b in __interceptor_malloc (/home/src/dhcpd-pools/dhcpd-pools+0x49c58b) #1 0x4cbbcd in xmalloc /home/src/dhcpd-pools/lib/xmalloc.c:41:13 #2 0x4bb801 in parse_leases /home/src/dhcpd-pools/src/getdata.c:96:9 #3 0x4bb337 in main /home/src/dhcpd-pools/src/dhcpd-pools.c:268:2 #4 0x7f51909bf03f in __libc_start_main (/usr/lib/libc.so.6+0x2003f) Signed-off-by: Sami Kerola --- src/getdata.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/getdata.c b/src/getdata.c index 56d5088..976f0c1 100644 --- a/src/getdata.c +++ b/src/getdata.c @@ -94,7 +94,9 @@ int parse_leases(void) } line = xmalloc(sizeof(char) * MAXLEN); + line[0] = '\0'; ipstring = xmalloc(sizeof(char) * MAXLEN); + ipstring[0] = '\0'; if (config.output_format[0] == 'X' || config.output_format[0] == 'J') { ethernets = true; }