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

Andrew Clayton andrew at digital-domain.net
Thu Jun 16 01:00:57 UTC 2022


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)));
 
         inet->start = nxt_inet_addr(addr.start, addr.length) & inet->end;
         if (nxt_slow_path(inet->start == INADDR_NONE)) {
-- 
2.36.1



More information about the unit mailing list