Skip to content

Commit 0d99744

Browse files
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 <[email protected]>
1 parent 2e61525 commit 0d99744

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/nxt_http_route.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,10 @@ nxt_http_route_pattern(nxt_http_request_t *r, nxt_http_route_pattern_t *pattern,
21342134
return 0;
21352135
}
21362136

2137+
if (nxt_slow_path(start == NULL)) {
2138+
return 1;
2139+
}
2140+
21372141
nxt_assert(pattern->u.pattern_slices != NULL);
21382142

21392143
pattern_slices = pattern->u.pattern_slices;

0 commit comments

Comments
 (0)