From 6d08c3b300e97e1b334f84a2eef4c9af190a51d9 Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Fri, 19 Jul 2013 21:54:02 +0200 Subject: [PATCH] Report broken netlink messages in debug mode --- lib/debug.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/debug.c b/lib/debug.c index 1350053..3aa5a99 100644 --- a/lib/debug.c +++ b/lib/debug.c @@ -236,6 +236,19 @@ ipset_debug_msg(const char *dir, void *buffer, int len) int cmd, nfmsglen = MNL_ALIGN(sizeof(struct nfgenmsg)); debug = 0; + if (!mnl_nlmsg_ok(nlh, len)) { + fprintf(stderr, "Broken message received!\n"); + if (len < (int)sizeof(struct nlmsghdr)) { + fprintf(stderr, "len (%d) < sizeof(struct nlmsghdr) (%d)\n", + len, (int)sizeof(struct nlmsghdr)); + } else if (nlh->nlmsg_len < sizeof(struct nlmsghdr)) { + fprintf(stderr, "nlmsg_len (%u) < sizeof(struct nlmsghdr) (%d)\n", + nlh->nlmsg_len, (int)sizeof(struct nlmsghdr)); + } else if ((int)nlh->nlmsg_len > len) { + fprintf(stderr, "nlmsg_len (%u) > len (%d)\n", + nlh->nlmsg_len, len); + } + } while (mnl_nlmsg_ok(nlh, len)) { switch (nlh->nlmsg_type) { case NLMSG_NOOP: -- 2.40.0