From: Cyrill Gorcunov Date: Wed, 2 Nov 2016 13:14:55 +0000 (+0300) Subject: libnetlink: Add test for error code returned from netlink reply X-Git-Tag: v4.10.0~119 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f66764e308e9c645b3fb2d1cfbb7fb207eb5de1;p=thirdparty%2Fiproute2.git libnetlink: Add test for error code returned from netlink reply In case if some diag module is not present in the system, say the kernel is not modern enough, we simply skip the error code reported. Instead we should check for data length in NLMSG_DONE and process unsupported case. Signed-off-by: Cyrill Gorcunov --- diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 21a763632..a5db168e5 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -319,6 +319,22 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth, dump_intr = 1; if (h->nlmsg_type == NLMSG_DONE) { + if (rth->proto == NETLINK_SOCK_DIAG) { + if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) { + fprintf(stderr, "DONE truncated\n"); + return -1; + } else { + int len = *(int *)NLMSG_DATA(h); + if (len < 0) { + errno = -len; + if (errno == ENOENT || + errno == EOPNOTSUPP) + return -1; + perror("RTNETLINK answers"); + return len; + } + } + } found_done = 1; break; /* process next filter */ }