bugfix: SIGSEGV in receiveuntil __gc on aborted multipart upload.#2504
Conversation
read_error_retval_handler calls finalize_read_part directly when the receiveuntil iterator's recv errors. That clears u->buf_in but leaves cp->upstream live with cp->state > 0. Later GC fires cleanup_compiled_pattern -> read_prepare, which derefs the now-NULL u->buf_in. Mirror tcp_finalize's cp->upstream = NULL detach so __gc's existing `if (u != NULL)` guard short-circuits. Backtrace: ngx_http_lua_socket_tcp_read_prepare ngx_http_lua_socket_cleanup_compiled_pattern lj_BC_FUNCC gc_call_finalizer gc_finalize gc_onestep lj_gc_fullgc lua_gc lj_cf_collectgarbage lj_BC_FUNCC ngx_http_lua_run_thread ngx_http_lua_socket_tcp_resume_helper ngx_http_lua_access_handler ngx_http_core_access_phase ngx_http_core_run_phases ngx_http_lua_socket_tcp_read ngx_http_request_handler ngx_epoll_process_events ngx_process_events_and_timers ngx_worker_process_cycle ngx_spawn_process ngx_start_worker_processes ngx_master_process_cycle main
|
Standalone pytest + nginx config that reliably reproduces the crash on the unpatched module (20/20) and passes with this PR applied. Useful until/unless this gets folded into the upstream Drop both files in the same directory and run: The client sends a Backtrace (production, vendored nginx + lua-nginx-module 0.10.26):
|
read_error_retval_handler calls finalize_read_part directly when the receiveuntil iterator's recv errors. That clears u->buf_in but leaves cp->upstream live with cp->state > 0. Later GC fires cleanup_compiled_pattern -> read_prepare, which derefs the now-NULL u->buf_in.
Mirror tcp_finalize's cp->upstream = NULL detach so __gc's existing
if (u != NULL)guard short-circuits.Backtrace:
ngx_http_lua_socket_tcp_read_prepare
ngx_http_lua_socket_cleanup_compiled_pattern
lj_BC_FUNCC
gc_call_finalizer
gc_finalize
gc_onestep
lj_gc_fullgc
lua_gc
lj_cf_collectgarbage
lj_BC_FUNCC
ngx_http_lua_run_thread
ngx_http_lua_socket_tcp_resume_helper
ngx_http_lua_access_handler
ngx_http_core_access_phase
ngx_http_core_run_phases
ngx_http_lua_socket_tcp_read
ngx_http_request_handler
ngx_epoll_process_events
ngx_process_events_and_timers
ngx_worker_process_cycle
ngx_spawn_process
ngx_start_worker_processes
ngx_master_process_cycle
main
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.