From c5bc52b715d4037af1ab97a493e2c405513d8d0c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 14 Jul 2024 12:35:18 +0100 Subject: [PATCH 1/2] sapi/apache2: apache env with walk_to_top going to the parent request. up to now, we walked down the oldest request we can find, now if the current request is a subrequest, we just reach to its parent directly. Previous workflow for setting env affects a possible non main request within those internal redirections. --- sapi/apache2handler/php_functions.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index b0434f2e43223..8f52f2295d32f 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -243,13 +243,13 @@ PHP_FUNCTION(apache_note) /* {{{ Set an Apache subprocess_env variable */ /* - * XXX this doesn't look right. shouldn't it be the parent ?*/ + */ PHP_FUNCTION(apache_setenv) { php_struct *ctx; char *variable=NULL, *string_val=NULL; size_t variable_len, string_val_len; - bool walk_to_top = 0; + bool walk_to_top = false; int arg_count = ZEND_NUM_ARGS(); request_rec *r; @@ -262,8 +262,8 @@ PHP_FUNCTION(apache_setenv) r = ctx->r; if (arg_count == 3) { if (walk_to_top) { - while(r->prev) { - r = r->prev; + if (r->main) { + r = r->main; } } } @@ -276,14 +276,13 @@ PHP_FUNCTION(apache_setenv) /* {{{ Get an Apache subprocess_env variable */ /* - * XXX: shouldn't this be the parent not the 'prev' */ PHP_FUNCTION(apache_getenv) { php_struct *ctx; char *variable; size_t variable_len; - bool walk_to_top = 0; + bool walk_to_top = false; int arg_count = ZEND_NUM_ARGS(); char *env_val=NULL; request_rec *r; @@ -297,8 +296,8 @@ PHP_FUNCTION(apache_getenv) r = ctx->r; if (arg_count == 2) { if (walk_to_top) { - while(r->prev) { - r = r->prev; + if (r->main) { + r = r->main; } } } From 01ff68449c548a3d5b38b4c4e1840389ba9b5714 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 14 Jul 2024 22:11:00 +0100 Subject: [PATCH 2/2] apache_response_headers/apache_request_headers using ZPP --- sapi/apache2handler/php_functions.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index 8f52f2295d32f..d6464317c3df1 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -173,9 +173,7 @@ PHP_FUNCTION(apache_request_headers) const apr_array_header_t *arr; char *key, *val; - if (zend_parse_parameters_none() == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value); @@ -196,9 +194,7 @@ PHP_FUNCTION(apache_response_headers) const apr_array_header_t *arr; char *key, *val; - if (zend_parse_parameters_none() == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_NONE(); array_init(return_value);