]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virarptable: Fix check for message length
authorMartin Kletzander <mkletzan@redhat.com>
Fri, 16 Aug 2024 11:59:15 +0000 (13:59 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 19 Aug 2024 10:14:26 +0000 (12:14 +0200)
The previous check was all wrong since it calculated the how long would
the netlink message be if the netlink header was the payload and then
subtracted that from the whole message length, a variable that was not
used later in the code.  This check can fail if there are no additional
payloads, struct rtattr in particular, which we are parsing later,
however the RTA_OK macro would've caught that anyway.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/util/virarptable.c

index d8e41c5a866852bf7f954e3f2bc386e8363f868c..45ee76766fe7924e35f2643d234817f01034b19c 100644 (file)
@@ -81,10 +81,9 @@ virArpTableGet(void)
     for (; NLMSG_OK(nh, msglen); nh = NLMSG_NEXT(nh, msglen)) {
         VIR_WARNINGS_RESET
         struct ndmsg *r = NLMSG_DATA(nh);
-        int len = nh->nlmsg_len;
         void *addr;
 
-        if ((len -= NLMSG_LENGTH(sizeof(*nh))) < 0) {
+        if (nh->nlmsg_len < NLMSG_SPACE(sizeof(*r))) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("wrong nlmsg len"));
             goto cleanup;