From 17c51c6a866d2c1593df02a5a57665628a0bb0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wang=20Xin-yu=20=28=E7=8E=8B=E6=98=95=E5=AE=87=29?= Date: Tue, 29 Mar 2016 12:31:51 +0000 Subject: [PATCH 1/3] fix stack buffer overflow when convert between in6_addr --- src/conninode.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/conninode.cpp b/src/conninode.cpp index 5a8b17b..430162f 100644 --- a/src/conninode.cpp +++ b/src/conninode.cpp @@ -60,8 +60,8 @@ std::map conninode; */ void addtoconninode(char *buffer) { short int sa_family; - struct in6_addr result_addr_local; - struct in6_addr result_addr_remote; + struct in6_addr result_addr_local = {}; + struct in6_addr result_addr_remote = {}; char rem_addr[128], local_addr[128]; int local_port, rem_port; @@ -102,8 +102,8 @@ void addtoconninode(char *buffer) { if ((in6_local.s6_addr32[0] == 0x0) && (in6_local.s6_addr32[1] == 0x0) && (in6_local.s6_addr32[2] == 0xFFFF0000)) { /* IPv4-compatible address */ - result_addr_local = *((struct in6_addr *)&(in6_local.s6_addr32[3])); - result_addr_remote = *((struct in6_addr *)&(in6_remote.s6_addr32[3])); + result_addr_local.s6_addr32[0] = in6_local.s6_addr32[3]; + result_addr_remote.s6_addr32[0] = in6_remote.s6_addr32[3]; sa_family = AF_INET; } else { /* real IPv6 address */ From 07bd32e878338de4f46ab25adcdcf95e716e1344 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Thu, 31 Mar 2016 07:51:46 +0200 Subject: [PATCH 2/3] Add -Wno-missing-field-initializers to build to suppress spurious warning --- src/MakeApp.mk | 2 +- src/MakeLib.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MakeApp.mk b/src/MakeApp.mk index f0d8040..2307d6e 100644 --- a/src/MakeApp.mk +++ b/src/MakeApp.mk @@ -9,7 +9,7 @@ all: nethogs decpcap_test # nethogs_testsum CFLAGS?=-Wall -Wextra -CXXFLAGS?=-Wall -Wextra +CXXFLAGS?=-Wall -Wextra -Wno-missing-field-initializers OBJS=packet.o connection.o process.o decpcap.o cui.o inode2prog.o conninode.o devices.o diff --git a/src/MakeLib.mk b/src/MakeLib.mk index 2a39a06..4400a75 100644 --- a/src/MakeLib.mk +++ b/src/MakeLib.mk @@ -24,12 +24,12 @@ ifeq ($(DEBUG),1) $(info Bulding debug version) ODIR:=$(ODIR_BASE)/lib/debug CFLAGS?=-Wall -Wextra -O0 -g -fPIC $(VISIBILITY) - CXXFLAGS?=-Wall -Wextra --std=c++0x -O0 -g -fPIC $(VISIBILITY) $(CXXINCLUDES) + CXXFLAGS?=-Wall -Wextra -Wno-missing-field-initializers --std=c++0x -O0 -g -fPIC $(VISIBILITY) $(CXXINCLUDES) else # Release mode options ODIR:=$(ODIR_BASE)/lib/release CFLAGS?=-Wall -Wextra -O3 -fPIC $(VISIBILITY) - CXXFLAGS?=-Wall -Wextra --std=c++0x -O3 -fPIC $(VISIBILITY) $(CXXINCLUDES) + CXXFLAGS?=-Wall -Wextra -Wno-missing-field-initializers --std=c++0x -O3 -fPIC $(VISIBILITY) $(CXXINCLUDES) endif OBJ_NAMES= libnethogs.o packet.o connection.o process.o decpcap.o inode2prog.o conninode.o devices.o From db2da627df15602ff1c8c06aaa8028793b89e705 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Thu, 31 Mar 2016 07:55:52 +0200 Subject: [PATCH 3/3] Don't redefine TH_FLAGS Fixes compiler warning: packet.cpp:127:9: warning: 'TH_FLAGS' macro redefined ^ /usr/include/netinet/tcp.h:103:9: note: previous definition is here --- src/packet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/packet.cpp b/src/packet.cpp index 930a449..5946740 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -124,7 +124,6 @@ struct tcp_hdr { #define TH_URG 0x20 #define TH_ECE 0x40 #define TH_CWR 0x80 -#define TH_FLAGS (TH_FIN | TH_SYN | TH_RST | TH_ACK | TH_URG | TH_ECE | TH_CWR) u_short th_win; /* window */ u_short th_sum; /* checksum */ u_short th_urp; /* urgent pointer */