diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2024-01-31 15:15:12 +0000 |
---|---|---|
committer | andrey-zelenkov <xim.andrew@gmail.com> | 2024-03-11 16:51:35 +0000 |
commit | 0d99744debf75ec4434e10624cc0e59336584a29 (patch) | |
tree | 76b542ee6a07d038662cf3e3971df009a422e765 | |
parent | 2e615250932b5cda65564a5e3bbb097c26dfb030 (diff) | |
download | unit-0d99744debf75ec4434e10624cc0e59336584a29.tar.gz unit-0d99744debf75ec4434e10624cc0e59336584a29.tar.bz2 |
Router: match when pattern and tested string are both zero length
Otherwise, undefined behaviour will be triggered.
Can be reproduced by test/test_routing.py::test_routes_match_host_empty
with enabled UndefinedBehaviorSanitizer:
src/nxt_http_route.c:2141:17: runtime error: applying zero offset to null pointer
#0 0x100562588 in nxt_http_route_test_rule nxt_http_route.c:2091
#1 0x100564ed8 in nxt_http_route_handler nxt_http_route.c:1574
#2 0x10055188c in nxt_http_request_action nxt_http_request.c:570
#3 0x10052b1a0 in nxt_h1p_request_body_read nxt_h1proto.c:998
#4 0x100449c38 in nxt_event_engine_start nxt_event_engine.c:542
#5 0x100436828 in nxt_thread_trampoline nxt_thread.c:126
#6 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
#7 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_route.c:2141:17
Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r-- | src/nxt_http_route.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/nxt_http_route.c b/src/nxt_http_route.c index 4a64d5c1..d16d5803 100644 --- a/src/nxt_http_route.c +++ b/src/nxt_http_route.c @@ -2134,6 +2134,10 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern, return 0; } + if (nxt_slow_path(start == NULL)) { + return 1; + } + nxt_assert(pattern->u.pattern_slices != NULL); pattern_slices = pattern->u.pattern_slices; |