mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-04 00:00:14 -04:00
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.
This commit is contained in:
parent
f738753abc
commit
8d34e55375
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user