]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp6-client: Use offsetof() instead of sizeof() 7885/head
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 15 Jan 2018 15:37:52 +0000 (17:37 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 15 Jan 2018 16:00:33 +0000 (18:00 +0200)
The slightly modified review comments say that "...in theory
offsetof(DHCP6Option, data) is nicer than sizeof(DHCP6Option)
because the former removes alignment artifacts. In this
specific case there are no alignment whitespaces hence it's
fine, but out of a matter of principle offsetof() is preferred
over sizeof() in cases like this..."

src/libsystemd-network/sd-dhcp6-client.c

index 0584059fec8c183e4076d89cca2e9694929828c1..f98a18268f9476fbb2dd5963b6fd6f15e4665659 100644 (file)
@@ -788,7 +788,8 @@ static int client_parse_message(
                 uint8_t *optval;
                 be32_t iaid_lease;
 
-                if (len < sizeof(DHCP6Option) || len < sizeof(DHCP6Option) + be16toh(option->len))
+                if (len < offsetof(DHCP6Option, data) ||
+                    len < offsetof(DHCP6Option, data) + be16toh(option->len))
                         return -ENOBUFS;
 
                 optcode = be16toh(option->code);