[PATCH 07/11] Route: avoided undefined behaviour.

Alejandro Colomar alx.manpages at gmail.com
Thu Jun 16 15:55:58 UTC 2022



On 6/16/22 03:00, Andrew Clayton wrote:
> In src/nxt_http_route_addr.c::nxt_http_route_addr_pattern_parse() there
> was potentially undefined behaviour when shifting a 32 bit value by 32
> bits, this could happen if cidr_prefix was 0.
> 
> Promote the shiftee to unsigned long to avoid this issue.
> ---
>   src/nxt_http_route_addr.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/nxt_http_route_addr.c b/src/nxt_http_route_addr.c
> index 2907a90..67c781a 100644
> --- a/src/nxt_http_route_addr.c
> +++ b/src/nxt_http_route_addr.c
> @@ -233,7 +233,7 @@ nxt_http_route_addr_pattern_parse(nxt_mp_t *mp,
>           }
>   
>           addr.length = delim - addr.start;
> -        inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFF << (32 - cidr_prefix)));
> +        inet->end = htonl(0xFFFFFFFF & (0xFFFFFFFFUL << (32 - cidr_prefix)));

Do we support platforms with 32-bit long?  I'm not sure.  To be safe, 
I'd use ULL.  Makes sense?

>   
>           inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end;
>           if (nxt_slow_path(inet->start == INADDR_NONE)) {

-- 
Alejandro Colomar
<http://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20220616/20ff3d09/attachment.bin>


More information about the unit mailing list