Skip to content

Fix GH-17509: Apache parent and subrequest double bailout #17653

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Zend/zend_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ struct _zend_executor_globals {
#define EG_FLAGS_IN_SHUTDOWN (1<<0)
#define EG_FLAGS_OBJECT_STORE_NO_REUSE (1<<1)
#define EG_FLAGS_IN_RESOURCE_SHUTDOWN (1<<2)
#define EG_FLAGS_IN_EXECUTOR_SHUTDOWN (1<<3)

struct _zend_ini_scanner_globals {
zend_file_handle *yy_in;
Expand Down
4 changes: 4 additions & 0 deletions Zend/zend_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,10 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func

CWD_API zend_result virtual_chdir(const char *path) /* {{{ */
{
if (CWDG(cwd).cwd == NULL) {
return FAILURE;
}

return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, CWD_REALPATH) ? FAILURE : SUCCESS;
}
/* }}} */
Expand Down
6 changes: 5 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,11 @@ void php_request_shutdown(void *dummy)
{
bool report_memleaks;

EG(flags) |= EG_FLAGS_IN_SHUTDOWN;
if (EG(flags) & EG_FLAGS_IN_EXECUTOR_SHUTDOWN) {
return;
}

EG(flags) |= EG_FLAGS_IN_SHUTDOWN | EG_FLAGS_IN_EXECUTOR_SHUTDOWN;

report_memleaks = PG(report_memleaks);

Expand Down
9 changes: 9 additions & 0 deletions sapi/apache2handler/sapi_apache2.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ static int php_handler(request_rec *r)
apr_bucket *bucket;
apr_status_t rv;
request_rec * volatile parent_req = NULL;
JMP_BUF *parent_bailout = NULL;
#ifdef ZTS
/* initial resource fetch */
(void)ts_resource(0);
Expand Down Expand Up @@ -665,6 +666,10 @@ static int php_handler(request_rec *r)
ap_add_cgi_vars(r);
}

if (parent_bailout == NULL && parent_req && EG(bailout)) {
parent_bailout = EG(bailout);
}

zend_first_try {

if (ctx == NULL) {
Expand Down Expand Up @@ -749,6 +754,10 @@ zend_first_try {
ctx->r = parent_req;
}

if (parent_bailout) {
EG(bailout) = parent_bailout;
}

return OK;
}

Expand Down
Loading