Unverified Commit 6dcd23e2 by Stéphane Graber Committed by GitHub

Merge pull request #3758 from brauner/2021-03-31/fixes

confile: cap to last bit in set_config_net_ipv4_address()
parents ea35e2cc 36513635
......@@ -781,22 +781,22 @@ static int set_config_net_ipv4_address(const char *key, const char *value,
}
/* No prefix specified, determine it from the network class. */
if (prefix) {
ret = 0;
if (prefix)
ret = lxc_safe_uint(prefix, &inetdev->prefix);
if (ret < 0)
return ret;
} else {
else
inetdev->prefix = config_ip_prefix(&inetdev->addr);
}
if (inetdev->prefix > 32)
if (ret || inetdev->prefix > 32)
return ret_errno(EINVAL);
/* If no broadcast address, let compute one from the
* prefix and address.
*/
/* If no broadcast address, compute one from the prefix and address. */
if (!bcast) {
unsigned int shift = LAST_BIT_PER_TYPE(inetdev->prefix);
inetdev->bcast.s_addr = inetdev->addr.s_addr;
inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> inetdev->prefix);
if (inetdev->prefix < shift)
shift = inetdev->prefix;
inetdev->bcast.s_addr |= htonl(INADDR_BROADCAST >> shift);
}
list->elem = inetdev;
......
......@@ -737,4 +737,8 @@ enum {
#define __aligned_u64 __u64 __attribute__((aligned(8)))
#endif
#define BITS_PER_BYTE 8
#define BITS_PER_TYPE(type) (sizeof(type) * 8)
#define LAST_BIT_PER_TYPE(type) (BITS_PER_TYPE(type) - 1)
#endif /* __LXC_MACRO_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment