From 201d065f52487af767b1af12616d0fed236ee196 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Thu, 16 Aug 2018 22:55:34 -0400 Subject: [PATCH 1/3] [server] fix Clang compiler warning to remove extraneous var increment utils.c:217:13: warning: variable 'i' is incremented both in the loop header and in the loop body [-Wfor-loop-analysis] i++; ^ utils.c:213:34: note: incremented here for (i=0; i Date: Fri, 17 Aug 2018 20:51:36 -0400 Subject: [PATCH 2/3] [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; From b0465998490afed48feb80ef885fb6b0d2db49f3 Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Fri, 17 Aug 2018 21:16:12 -0400 Subject: [PATCH 3/3] [build] add MemorySanitizer support --- configure.ac | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e2b7b35c..238e7128 100644 --- a/configure.ac +++ b/configure.ac @@ -189,7 +189,7 @@ if test "x$want_asan_support" = "xyes"; then FKO_CHECK_COMPILER_ARG([-fsanitize=address -fno-omit-frame-pointer]) fi -dnl Decide whether or not to enable MemorySanitizer support +dnl Decide whether or not to enable UndefineSanitizer support dnl want_ubsan_support=no AC_ARG_ENABLE([ubsan-support], @@ -202,6 +202,19 @@ if test "x$want_ubsan_support" = "xyes"; then FKO_CHECK_COMPILER_ARG([-fsanitize=undefined]) fi +dnl Decide whether or not to enable MemorySanitizer support +dnl +want_memsan_support=no +AC_ARG_ENABLE([memsan-support], + [AS_HELP_STRING([--enable-memsan-support], + [Build fwknop binaries with MemorySanitizer support @<:@default is to disable@:>@])], + [want_memsan_support=$enableval], + []) + +if test "x$want_memsan_support" = "xyes"; then + FKO_CHECK_COMPILER_ARG([-fsanitize=memory -fsanitize-memory-track-origins=2]) +fi + dnl Decide whether or not force 32-bit mode dnl want_32bit_mode=no