Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some issues found by tests with enabled UndefinedBehaviorSanitizer #1109

Merged
merged 7 commits into from
Mar 11, 2024

Commits on Feb 23, 2024

  1. 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
        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
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    2dfba77 View commit details
    Browse the repository at this point in the history
  2. NJS: avoiding arithmetic ops with NULL pointer in r->args

    Can be reproduced by test/test_rewrite.py::test_rewrite_njs
    with enabled UndefinedBehaviorSanitizer:
    
    src/nxt_http_js.c:169:52: runtime error: applying zero offset to null pointer
        #0 0x10255b044 in nxt_http_js_ext_get_args nxt_http_js.c:169
        nginx#1 0x102598ad0 in njs_value_property njs_value.c:1175
        nginx#2 0x10259c2c8 in njs_vm_object_prop njs_vm.c:1398
        nginx#3 0x102559d74 in nxt_js_call nxt_js.c:445
        nginx#4 0x1023c0da0 in nxt_tstr_query nxt_tstr.c:276
        nginx#5 0x102516ec4 in nxt_http_rewrite nxt_http_rewrite.c:56
        nginx#6 0x1024fd86c in nxt_http_request_action nxt_http_request.c:565
        nginx#7 0x1024d71b0 in nxt_h1p_request_body_read nxt_h1proto.c:998
        nginx#8 0x1023f5c48 in nxt_event_engine_start nxt_event_engine.c:542
        nginx#9 0x1023e2838 in nxt_thread_trampoline nxt_thread.c:126
        nginx#10 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
        nginx#11 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)
    
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_js.c:169:52
    
    Same fix was introduced in NJS:
    <http://hg.nginx.org/njs/rev/4fba78789fe4>
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    edb69d5 View commit details
    Browse the repository at this point in the history
  3. Fixed undefined behaviour in left shift of int value

    Found by UndefinedBehaviorSanitizer:
    
    src/nxt_random.c:151:31: runtime error: left shift of 140 by 24 places cannot be represented in type 'int'
        #0 0x104f78968 in nxt_random nxt_random.c:151
        nginx#1 0x104f58a98 in nxt_shm_open nxt_port_memory.c:377
        nginx#2 0x10503e24c in nxt_controller_conf_send nxt_controller.c:617
        nginx#3 0x105041154 in nxt_controller_process_request nxt_controller.c:1109
        nginx#4 0x104fcdc48 in nxt_event_engine_start nxt_event_engine.c:542
        nginx#5 0x104f27254 in main nxt_main.c:35
        nginx#6 0x180fbd0dc  (<unknown module>)
    
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_random.c:151:31
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    e9c12c2 View commit details
    Browse the repository at this point in the history
  4. Avoiding arithmetic ops with NULL pointer in nxt_http_arguments_parse

    Can be reproduced by test/test_variables.py::test_variables_dynamic_arguments
    with enabled UndefinedBehaviorSanitizer:
    
    src/nxt_http_request.c:961:17: runtime error: applying zero offset to null pointer
        #0 0x1050d95a4 in nxt_http_arguments_parse nxt_http_request.c:961
        nginx#1 0x105102bf8 in nxt_http_var_arg nxt_http_variables.c:621
        nginx#2 0x104f95d74 in nxt_var_interpreter nxt_var.c:507
        nginx#3 0x104f98c98 in nxt_tstr_query nxt_tstr.c:265
        nginx#4 0x1050abfd8 in nxt_router_access_log_writer nxt_router_access_log.c:194
        nginx#5 0x1050d81f4 in nxt_http_request_close_handler nxt_http_request.c:838
        nginx#6 0x104fcdc48 in nxt_event_engine_start nxt_event_engine.c:542
        nginx#7 0x104fba838 in nxt_thread_trampoline nxt_thread.c:126
        nginx#8 0x18133e030 in _pthread_start+0x84 (libsystem_pthread.dylib:arm64e+0x7030)
        nginx#9 0x181338e38 in thread_start+0x4 (libsystem_pthread.dylib:arm64e+0x1e38)
    
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/nxt_http_request.c:961:17
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    5eeaf1f View commit details
    Browse the repository at this point in the history
  5. Avoiding arithmetic ops with NULL pointer in nxt_port_mmap_get

    Can be reproduced by test/test_settings.py::test_settings_send_timeout
    with enabled UndefinedBehaviorSanitizer.
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    e14f64b View commit details
    Browse the repository at this point in the history
  6. Initialize port_impl only when it is needed

    Found by UndefinedBehaviorSanitizer.
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    3431dfe View commit details
    Browse the repository at this point in the history
  7. Avoiding arithmetic ops with NULL pointer in nxt_unit_mmap_get

    Found by UndefinedBehaviorSanitizer.
    
    Reviewed-by: Andrew Clayton <[email protected]>
    andrey-zelenkov committed Feb 23, 2024
    Configuration menu
    Copy the full SHA
    887fa46 View commit details
    Browse the repository at this point in the history