]> the.earth.li Git - mqtt-arp.git/commitdiff
Fix alignment when parsing Netlink messages
authorJonathan McDowell <noodles@earth.li>
Wed, 6 Jun 2018 17:30:56 +0000 (18:30 +0100)
committerJonathan McDowell <noodles@earth.li>
Wed, 6 Jun 2018 17:30:56 +0000 (18:30 +0100)
The Netlink header should be treated as NLA_HDRLEN in length, and
NLA_ALIGN() used to deal with padding after attributes.

mqtt-arp.c

index 19da3304117ace9589b3d17cf148cf89484aaaad..ba977b424ca6883c7a6983326c2eca73d1ad8489 100644 (file)
@@ -197,15 +197,15 @@ void main_loop(struct ma_config *config, struct mosquitto *mosq, int sock)
                                        nd->ndm_type);
                        }
                        attr = (struct nlattr *) (nd + 1);
-                       while (attr->nla_len > 0) {
-                               data = (((uint8_t *) attr) + 4);
+                       while (((uint8_t *) attr - buf) < hdr->nlmsg_len) {
+                               data = (((uint8_t *) attr) + NLA_HDRLEN);
                                if (attr->nla_type == NDA_LLADDR &&
                                        nd->ndm_state == NUD_REACHABLE) {
                                        mqtt_mac_presence(config, mosq,
                                                        data, true);
                                }
-                               attr = (struct nlattr *)
-                                       (((uint8_t *) attr) + attr->nla_len);
+                               attr = (struct nlattr *) (((uint8_t *) attr) +
+                                               NLA_ALIGN(attr->nla_len));
                        }
                        break;
                case RTM_DELNEIGH: