When fw3_bitlen2netmask() is invoked with a bit length of 128, the next
byte after the end of struct in6_addr is errorneously zeroed, leading to
a heap corruption on at least x86_64 with uclibc and possibly others.
Prevent the invalid writes by explicitely testing for a bit count < 128.
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
i = abs(bits);
memset(v6->s6_addr, 0xff, i / 8);
- memset(v6->s6_addr + (i / 8) + 1, 0, (128 - i) / 8);
- v6->s6_addr[i / 8] = 0xff << (8 - (i & 7));
+
+ if (i < 128)
+ {
+ memset(v6->s6_addr + (i / 8) + 1, 0, (128 - i) / 8);
+ v6->s6_addr[i / 8] = 0xff << (8 - (i & 7));
+ }
if (bits < 0)
for (i = 0; i < 16; i++)