]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
libnetlink: validate nlmsg header length first
authorMax Kunzelmann <maxdev@posteo.de>
Tue, 7 Nov 2023 01:20:55 +0000 (01:20 +0000)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 9 Nov 2023 17:03:57 +0000 (09:03 -0800)
Validate the nlmsg header length before accessing the nlmsg payload
length.

Fixes: 892a25e286fb ("libnetlink: break up dump function")
Signed-off-by: Max Kunzelmann <maxdev@posteo.de>
Reviewed-by: Benny Baumann <BenBE@geshi.org>
Reviewed-by: Robert Geislinger <github@crpykng.de>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/libnetlink.c

index 7edcd28569fd1b49a8a592ec1c9bb740391d6d59..016482294276c334ff2392e0c80d8eff819533c3 100644 (file)
@@ -727,13 +727,15 @@ int rtnl_dump_request_n(struct rtnl_handle *rth, struct nlmsghdr *n)
 static int rtnl_dump_done(struct nlmsghdr *h,
                          const struct rtnl_dump_filter_arg *a)
 {
-       int len = *(int *)NLMSG_DATA(h);
+       int len;
 
        if (h->nlmsg_len < NLMSG_LENGTH(sizeof(int))) {
                fprintf(stderr, "DONE truncated\n");
                return -1;
        }
 
+       len = *(int *)NLMSG_DATA(h);
+
        if (len < 0) {
                errno = -len;