]> granicus.if.org Git - strace/commitdiff
netlink: avoid using unaligned sizeof(struct nlmsghdr) unnecessarily
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 17 Apr 2017 04:37:29 +0000 (04:37 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 17 Apr 2017 04:37:29 +0000 (04:37 +0000)
* netlink.c (NLMSG_HDRLEN): Redefine.
(decode_nlmsghdr_with_payload, decode_netlink): Use it instead
of sizeof(struct nlmsghdr).

netlink.c

index db6e43f8005cc1faa87066e56a96b43dc529e68c..dcd24629558530ce4f12a7cf0b375c0ea73612e6 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -32,6 +32,9 @@
 #include "xlat/netlink_flags.h"
 #include "xlat/netlink_types.h"
 
+#undef NLMSG_HDRLEN
+#define NLMSG_HDRLEN NLMSG_ALIGN(sizeof(struct nlmsghdr))
+
 /*
  * Fetch a struct nlmsghdr from the given address.
  */
@@ -78,11 +81,11 @@ decode_nlmsghdr_with_payload(struct tcb *const tcp,
 
        unsigned int nlmsg_len =
                nlmsghdr->nlmsg_len > len ? len : nlmsghdr->nlmsg_len;
-       if (nlmsg_len > sizeof(struct nlmsghdr)) {
+       if (nlmsg_len > NLMSG_HDRLEN) {
                tprints(", ");
 
-               printstrn(tcp, addr + sizeof(struct nlmsghdr),
-                         nlmsg_len - sizeof(struct nlmsghdr));
+               printstrn(tcp, addr + NLMSG_HDRLEN,
+                         nlmsg_len - NLMSG_HDRLEN);
        }
 
        tprints("}");
@@ -105,7 +108,7 @@ decode_netlink(struct tcb *const tcp, kernel_ulong_t addr, kernel_ulong_t len)
                kernel_ulong_t next_addr = 0;
                kernel_ulong_t next_len = 0;
 
-               if (nlmsghdr.nlmsg_len >= sizeof(struct nlmsghdr)) {
+               if (nlmsghdr.nlmsg_len >= NLMSG_HDRLEN) {
                        next_len = (len >= nlmsg_len) ? len - nlmsg_len : 0;
 
                        if (next_len && addr + nlmsg_len > addr)