Repository navigation
SAPI: Convert sapi_getenv to zend_string #23386
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -965,9 +965,9 @@ SAPI_API zend_stat_t *sapi_get_stat(void) | |
| } | ||
| } | ||
|
|
||
| SAPI_API char *sapi_getenv(const char *name, size_t name_len) | ||
| SAPI_API zend_string *sapi_getenv(const char *name, size_t name_len) | ||
| { | ||
| char *value, *tmp; | ||
| zend_string *value = NULL; | ||
|
|
||
| if (!sapi_module.getenv) { | ||
| return NULL; | ||
|
|
@@ -976,19 +976,18 @@ SAPI_API char *sapi_getenv(const char *name, size_t name_len) | |
| /* Ugly fix for HTTP_PROXY issue, see bug #72573 */ | ||
| return NULL; | ||
| } | ||
| tmp = sapi_module.getenv(name, name_len); | ||
| if (!tmp) { | ||
| value = sapi_module.getenv(name, name_len); | ||
| if (!value) { | ||
| return NULL; | ||
| } | ||
| value = estrdup(tmp); | ||
| #ifdef PHP_WIN32 | ||
| if (strlen(sapi_module.name) == sizeof("cgi-fcgi") - 1 && !strcmp(sapi_module.name, "cgi-fcgi")) { | ||
| /* XXX more modules to go, if needed. */ | ||
| free(tmp); | ||
| } | ||
| #endif | ||
| if (sapi_module.input_filter) { | ||
| sapi_module.input_filter(PARSE_STRING, name, &value, strlen(value), NULL); | ||
| /* XXX: pretty ugly because input filters aren't zend_string yet. */ | ||
| char *tmp = estrdup(ZSTR_VAL(value)); | ||
| size_t tmp_len = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not equal to the length? Third party filters not updating the length and doing a pass-thru will result in an empty string. This was previuosly not the case |
||
| sapi_module.input_filter(PARSE_STRING, name, &tmp, ZSTR_LEN(value), &tmp_len); | ||
| zend_string_release(value); | ||
| value = zend_string_init(tmp, tmp_len, 0); | ||
| efree(tmp); | ||
|
Comment on lines
+984
to
+990
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh this is fine as this is going to be somewhat temporary I imagine. |
||
| } | ||
| return value; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ static int parent = 1; | |
| static int request_body_fd; | ||
| static int fpm_is_running = 0; | ||
|
|
||
| static char *sapi_cgibin_getenv(const char *name, size_t name_len); | ||
| static zend_string *sapi_cgibin_getenv(const char *name, size_t name_len); | ||
| static void fastcgi_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback_type, void *arg); | ||
|
|
||
| #define PHP_MODE_STANDARD 1 | ||
|
|
@@ -461,16 +461,19 @@ static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes) /* {{{ */ | |
| } | ||
| /* }}} */ | ||
|
|
||
| static char *sapi_cgibin_getenv(const char *name, size_t name_len) /* {{{ */ | ||
| static zend_string *sapi_cgibin_getenv(const char *name, size_t name_len) /* {{{ */ | ||
| { | ||
| char *var = NULL; | ||
| /* if fpm has started, use fcgi env */ | ||
| if (fpm_is_running) { | ||
| fcgi_request *request = (fcgi_request*) SG(server_context); | ||
| return fcgi_getenv(request, name, name_len); | ||
| var = fcgi_getenv(request, name, name_len); | ||
| } | ||
|
|
||
| /* if fpm has not started yet, use std env */ | ||
| return getenv(name); | ||
| if (!var) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a behaviour change, a missing environment variable will now also fall back to here, not only when fpm isn't started yet |
||
| /* if fpm has not started yet, use std env */ | ||
| var = getenv(name); /* XXX: should we? */ | ||
| } | ||
| return var ? zend_string_init(var, strlen(var), 0) : NULL; | ||
|
Girgias marked this conversation as resolved.
Resolved
|
||
| } | ||
| /* }}} */ | ||
|
|
||
|
|
@@ -564,20 +567,27 @@ static void sapi_cgi_register_variables(zval *track_vars_array) /* {{{ */ | |
| if (CGIG(fix_pathinfo)) { | ||
| char *script_name = SG(request_info).request_uri; | ||
| unsigned int script_name_len = script_name ? strlen(script_name) : 0; | ||
| char *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1); | ||
| unsigned int path_info_len = path_info ? strlen(path_info) : 0; | ||
|
|
||
| php_self_len = script_name_len + path_info_len; | ||
| /* Concat script_name and path_info into php_self */ | ||
| php_self = zend_cstr_concat( | ||
| script_name, script_name_len, | ||
| path_info, path_info_len); | ||
| zend_string *path_info = sapi_cgibin_getenv("PATH_INFO", sizeof("PATH_INFO") - 1); | ||
|
NattyNarwhal marked this conversation as resolved.
Resolved
|
||
|
|
||
| if (path_info) { | ||
| php_self_len = script_name_len + ZSTR_LEN(path_info); | ||
| /* Concat script_name and path_info into php_self */ | ||
| php_self = zend_cstr_concat( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a future PR: it probably makes sense to change the |
||
| script_name, script_name_len, | ||
| ZSTR_VAL(path_info), ZSTR_LEN(path_info)); | ||
| } else { | ||
| php_self_len = script_name_len; | ||
| php_self = estrdup(script_name ? script_name : ""); | ||
| } | ||
|
|
||
| /* Build the special-case PHP_SELF variable for the CGI version */ | ||
| if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &php_self, php_self_len, &php_self_len)) { | ||
| php_register_variable_safe("PHP_SELF", php_self, php_self_len, track_vars_array); | ||
| } | ||
| efree(php_self); | ||
| if (path_info) { | ||
| zend_string_release(path_info); | ||
| } | ||
| } else { | ||
| php_self = SG(request_info).request_uri ? SG(request_info).request_uri : ""; | ||
| php_self_len = strlen(php_self); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if
path_infocould be azend_string*too but that requires changing theSG(request_info).request_uriglobal to zend_string first.