From 309abdab0c667a7d584ba4f085152806931a5ef9 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 17 Aug 2018 20:51:36 -0400 Subject: [PATCH] [server] Bug fix for MemorySanitizer error Replace strlcpy() with memcpy() since the source buffer is not a string. strlcpy() caught this anyway, but memcpy() usage is probably more valid. ==29766==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x562bc2e50420 in strlcpy /home/mbr/git/fwknop.git/common/strlcpy.c:61:3 #1 0x562bc2e25362 in process_packet /home/mbr/git/fwknop.git/server/process_packet.c:225:5 #2 0x7fa6173c9d57 (/lib64/libpcap.so.1+0x1fd57) #3 0x562bc2e2456a in pcap_capture /home/mbr/git/fwknop.git/server/pcap_capture.c:227:15 #4 0x562bc2e13ef0 in main /home/mbr/git/fwknop.git/server/fwknopd.c:296:13 #5 0x7fa61643724a in __libc_start_main /usr/src/debug/glibc-2.27-74-g68c1bf8097/csu/../csu/libc-start.c:308:16 #6 0x562bc2d9dec9 in _start (/home/mbr/git/fwknop.git/server/.libs/fwknopd+0x1dec9) Uninitialized value was created by a heap allocation #0 0x562bc2da6c84 in malloc (/home/mbr/git/fwknop.git/server/.libs/fwknopd+0x26c84) #1 0x7fa6173ca996 (/lib64/libpcap.so.1+0x20996) SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/mbr/git/fwknop.git/common/strlcpy.c:61:3 in strlcpy --- server/process_packet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/process_packet.c b/server/process_packet.c index 99fdc07c..32e99cb2 100644 --- a/server/process_packet.c +++ b/server/process_packet.c @@ -220,7 +220,9 @@ process_packet(PROCESS_PKT_ARGS_TYPE *args, PACKET_HEADER_META, /* Copy the packet for SPA processing */ - strlcpy((char *)opts->spa_pkt.packet_data, (char *)pkt_data, pkt_data_len+1); + memcpy((char *)opts->spa_pkt.packet_data, (char *)pkt_data, pkt_data_len); + opts->spa_pkt.packet_data[pkt_data_len] = '\0'; + opts->spa_pkt.packet_data_len = pkt_data_len; opts->spa_pkt.packet_proto = proto; opts->spa_pkt.packet_src_ip = src_ip;