[OpenWrt-Devel] [PATCH] firewall3: fix left shift on 64 bit systems in fw3_bitlen2netmask

Yousong Zhou yszhou4tech at gmail.com
Tue Jan 6 07:54:29 EST 2015


On 5 January 2015 at 22:58, Ulrich Weber <uweber.linux at gmail.com> wrote:
> otherwise 0.0.0.0/0 is set as 0.0.0.0/255.255.255.255 on x86_64
>
> Signed-off-by: Ulrich Weber <uw at ocedo.com>
> ---
>  utils.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/utils.c b/utils.c
> index 71a0f13..b2fbe02 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -803,7 +803,7 @@ fw3_bitlen2netmask(int family, int bits, void *mask)
>                         return false;
>
>                 v4 = mask;
> -               v4->s_addr = htonl(~((1 << (32 - abs(bits))) - 1));
> +               v4->s_addr = bits ? htonl(~((1 << (32 - abs(bits))) - 1)) : 0;
>

Quite a catch!  But the culprit should be that shifting a 32-bit
integer left/right by not less than 32 is supposed to be undefined
behaviour in C.

>                 if (bits < 0)
>                         v4->s_addr = ~v4->s_addr;
> --
> 1.9.1
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list