Skip to content

Commit

Permalink
Router: match when pattern and tested string are both zero length
Browse files Browse the repository at this point in the history
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
    nginx#1 0x100564ed8 in nxt_http_route_handler nxt_http_route.c:1574
    nginx#2 0x10055188c in nxt_http_request_action nxt_http_request.c:570
    nginx#3 0x10052b1a0 in nxt_h1p_request_body_read nxt_h1proto.c:998
    nginx#4 0x100449c38 in nxt_event_engine_start nxt_event_engine.c:542
    nginx#5 0x100436828 in nxt_thread_trampoline nxt_thread.c:126
    nginx#6 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
    nginx#7 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_route.c:2141:17
  • Loading branch information
andrey-zelenkov committed Jan 31, 2024
1 parent 69107e6 commit ea7c7f9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/nxt_http_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(length == 0)) {
return 1;
}

nxt_assert(pattern->u.pattern_slices != NULL);

pattern_slices = pattern->u.pattern_slices;
Expand Down

0 comments on commit ea7c7f9

Please sign in to comment.