From 51929c017ae38dbcd850573d53e2462a7cf88a2a Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 17 Apr 2017 04:37:29 +0000 Subject: [PATCH] netlink: avoid using unaligned sizeof(struct nlmsghdr) unnecessarily * netlink.c (NLMSG_HDRLEN): Redefine. (decode_nlmsghdr_with_payload, decode_netlink): Use it instead of sizeof(struct nlmsghdr). --- netlink.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/netlink.c b/netlink.c index db6e43f8..dcd24629 100644 --- 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) -- 2.40.0