From: Jozsef Kadlecsik Date: Fri, 19 Jul 2013 19:54:02 +0000 (+0200) Subject: Report broken netlink messages in debug mode X-Git-Tag: v6.20~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d08c3b300e97e1b334f84a2eef4c9af190a51d9;p=ipset Report broken netlink messages in debug mode --- 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: