diff mbox series

[1/2] monitor: use int length for NLMSG_NEXT

Message ID 20221013161424.505633-1-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] monitor: use int length for NLMSG_NEXT | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-alpine-ci-fetch success Fetch PR
prestwoj/iwd-ci-gitlint success GitLint
prestwoj/iwd-ci-fetch success Fetch PR
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-alpine-ci-makedistcheck success Make Distcheck
prestwoj/iwd-alpine-ci-build success Build - Configure
prestwoj/iwd-ci-clang fail Clang IWD - make FAIL: src/frame-xchg.c:363:29: error: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'int' [-Werror,-Wsign-compare] for (nlmsg = iov.iov_base; NLMSG_OK(nlmsg, nlmsg_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/linux/netlink.h:100:24: note: expanded from macro 'NLMSG_OK' (nlh)->nlmsg_len <= (len)) ~~~~~~~~~~~~~~~~ ^ ~~~ 1 error generated. make[1]: *** [Makefile:2408: src/frame-xchg.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make: *** [Makefile:1587: all] Error 2
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-alpine-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-alpine-ci-makecheck success Make Check
prestwoj/iwd-ci-incremental_build success Incremental Build with patches
prestwoj/iwd-alpine-ci-incremental_build success Incremental Build with patches
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

James Prestwood Oct. 13, 2022, 4:14 p.m. UTC
In all uses of NLMSG_{NEXT,OK,ALIGN} the length was unsigned
which is not what these macros expect. According to the docs
the length should be int type, so this was changed for all
uses in monitor.

The was causing random, somewhat rare, crashes in nlmon_receive.
---
 monitor/main.c  | 2 +-
 monitor/nlmon.c | 6 +++---
 monitor/nlmon.h | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/monitor/main.c b/monitor/main.c
index 9117fba3..78ee0d38 100644
--- a/monitor/main.c
+++ b/monitor/main.c
@@ -451,7 +451,7 @@  static int analyze_pcap(const char *pathname)
 
 	while (pcap_read(pcap, &tv, buf, snaplen, &len, &real_len)) {
 		struct nlmsghdr *nlmsg;
-		uint32_t aligned_len;
+		int aligned_len;
 		uint16_t arphrd_type;
 		uint16_t proto_type;
 
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
index 2222db09..573d16df 100644
--- a/monitor/nlmon.c
+++ b/monitor/nlmon.c
@@ -8080,7 +8080,7 @@  static void print_rtnl_msg(const struct timeval *tv,
 void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
 					const void *data, uint32_t size)
 {
-	uint32_t aligned_size = NLMSG_ALIGN(size);
+	int aligned_size = NLMSG_ALIGN(size);
 	const struct nlmsghdr *nlmsg;
 
 	update_time_offset(tv);
@@ -8112,7 +8112,7 @@  void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
 }
 
 void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv,
-					const void *data, uint32_t size)
+					const void *data, int size)
 {
 	const struct nlmsghdr *nlmsg;
 
@@ -8144,7 +8144,7 @@  static bool nlmon_receive(struct l_io *io, void *user_data)
 	unsigned char buf[8192];
 	unsigned char control[32];
 	ssize_t bytes_read;
-	uint32_t nlmsg_len;
+	int nlmsg_len;
 	int fd;
 
 	fd = l_io_get_fd(io);
diff --git a/monitor/nlmon.h b/monitor/nlmon.h
index f2f2892a..b8cb81db 100644
--- a/monitor/nlmon.h
+++ b/monitor/nlmon.h
@@ -41,7 +41,7 @@  void nlmon_destroy(struct nlmon *nlmon);
 void nlmon_print_rtnl(struct nlmon *nlmon, const struct timeval *tv,
 					const void *data, uint32_t size);
 void nlmon_print_genl(struct nlmon *nlmon, const struct timeval *tv,
-					const void *data, uint32_t size);
+					const void *data, int size);
 void nlmon_print_pae(struct nlmon *nlmon, const struct timeval *tv,
 					uint8_t type, int index,
 					const void *data, uint32_t size);