From 3c03564911d2e0b6e838fa40ba92716367bf17ed Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Mon, 15 Jan 2018 17:15:13 +0200 Subject: [PATCH 1/2] dhcp6: Fix valgrind nitpick about returned test case value Calling dhcp6_option_parse_address() will always return a value < 0 on error even though lt_valid remains unset. This is more than valgrind can safely detect, but let's fix the valgrind nitpick anyway. While fixing, use UINT32_MAX instead of ~0 on the same line. --- src/libsystemd-network/dhcp6-option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c index 784a11dc9d..7c6a6c4e08 100644 --- a/src/libsystemd-network/dhcp6-option.c +++ b/src/libsystemd-network/dhcp6-option.c @@ -358,7 +358,7 @@ int dhcp6_option_parse_ia(DHCP6Option *iaoption, DHCP6IA *ia) { int r = 0, status; uint16_t opt; size_t iaaddr_offset; - uint32_t lt_t1, lt_t2, lt_valid, lt_min = ~0; + uint32_t lt_t1, lt_t2, lt_valid = 0, lt_min = UINT32_MAX; assert_return(ia, -EINVAL); assert_return(!ia->addresses, -EINVAL); From ecf07fb748b76c182d0441366593f3c795f76578 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Mon, 15 Jan 2018 17:37:52 +0200 Subject: [PATCH 2/2] sd-dhcp6-client: Use offsetof() instead of sizeof() 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 0584059fec..f98a18268f 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -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);