host: Prevent overflow in host_create_netmask() if mask is 0 or 32/128
This commit is contained in:
@@ -597,13 +597,15 @@ host_t *host_create_netmask(int family, int netbits)
|
|||||||
this->address.sa_family = family;
|
this->address.sa_family = family;
|
||||||
update_sa_len(this);
|
update_sa_len(this);
|
||||||
|
|
||||||
bytes = (netbits + 7) / 8;
|
bytes = netbits / 8;
|
||||||
bits = (bytes * 8) - netbits;
|
bits = 8 - (netbits & 0x07);
|
||||||
|
|
||||||
memset(target, 0xff, bytes);
|
memset(target, 0xff, bytes);
|
||||||
memset(target + bytes, 0x00, len - bytes);
|
if (bytes < len)
|
||||||
target[bytes - 1] = bits ? (u_int8_t)(0xff << bits) : 0xff;
|
{
|
||||||
|
memset(target + bytes, 0x00, len - bytes);
|
||||||
|
target[bytes] = (u_int8_t)(0xff << bits);
|
||||||
|
}
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user