Fix Segmentation Fault when call fpm_get_status() #18662
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #18595 regression in 8.3.23 and 8.4.7
fix #18595
This bug is essentially like a race condition. Imagine there is one parent process (P) and two child processes (A and B), and assume each child’s max_requests is set to 1. Now suppose two clients quickly http requests in succession:
fpm_children_bury
->fpm_scoreboard_proc_free
to zero out A's process structurefpm_children_make
->fpm_resources_prepare
->fpm_scoreboard_proc_alloc
. infpm_scoreboard_proc_alloc
, the code setsmarking this new slot as “in use.” At this point,
used
field is1
butrequest_stage
field is still0
, because the latter isn’t initialized until the child actually begins toaccept a request
.Note
REMEMBER THE PROCESS A not reach
fpm_request_accepting
function yet!!fpm_get_status
->fpm_status_export_to_zval
.Since process A’s
used
field is set to1
,fpm_request_get_stage_name
gets called. However, the newly spawned process A hasn’t yet invokedfpm_request_accepting
, so itsrequest_stage field
is still0
.In this array, because
FPM_REQUEST_ACCEPTING
has the value 1, the string entries begin at index 1, and index 0 is left as NULL.Therefore, when
fpm_request_get_stage_name
is called with arequest_stage
of0
, it returnsNULL
, which leads to asegmentation fault.
So, I append new stage the
FPM_REQUEST_CREATING
and this is0
.Reproduce in 8.3.23
build
and do many client request burst.
Note
stage argument is 0!! and will occur segmentation fault when call strlen!
fixed bug branch
when request_stage field is
0
, but no segmentation fault