From 8d34e55375a5449624665eca75db82a01b1389ce Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 9 Apr 2014 17:09:55 +0200 Subject: [PATCH] attr: Don't shift the 32-bit netmask by 32 This is undefined behavior as per the C99 standard (sentence 1185): "If the value of the right operand is negative or is greater or equal to the width of the promoted left operand, the behavior is undefined." Apparently shifts may be done modulo the width on some platforms so a shift by 32 would not shift at all. --- src/libhydra/plugins/attr/attr_provider.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libhydra/plugins/attr/attr_provider.c b/src/libhydra/plugins/attr/attr_provider.c index a27fd57b11..c1788df94e 100644 --- a/src/libhydra/plugins/attr/attr_provider.c +++ b/src/libhydra/plugins/attr/attr_provider.c @@ -242,10 +242,13 @@ static void load_entries(private_attr_provider_t *this) { if (family == AF_INET) { /* IPv4 attributes contain a subnet mask */ - u_int32_t netmask; + u_int32_t netmask = 0; - mask = 32 - mask; - netmask = htonl((0xFFFFFFFF >> mask) << mask); + if (mask) + { /* shifting u_int32_t by 32 or more is undefined */ + mask = 32 - mask; + netmask = htonl((0xFFFFFFFF >> mask) << mask); + } data = chunk_cat("cc", host->get_address(host), chunk_from_thing(netmask)); } -- 2.47.2