Skip to content

Commit 84e4d2a

Browse files
authored
Refactor sapi_getenv() (#8786)
1 parent d5d0b07 commit 84e4d2a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

main/SAPI.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,29 +1007,30 @@ SAPI_API zend_stat_t *sapi_get_stat(void)
10071007

10081008
SAPI_API char *sapi_getenv(const char *name, size_t name_len)
10091009
{
1010+
char *value, *tmp;
1011+
1012+
if (!sapi_module.getenv) {
1013+
return NULL;
1014+
}
10101015
if (!strncasecmp(name, "HTTP_PROXY", name_len)) {
10111016
/* Ugly fix for HTTP_PROXY issue, see bug #72573 */
10121017
return NULL;
10131018
}
1014-
if (sapi_module.getenv) {
1015-
char *value, *tmp = sapi_module.getenv(name, name_len);
1016-
if (tmp) {
1017-
value = estrdup(tmp);
1019+
tmp = sapi_module.getenv(name, name_len);
1020+
if (!tmp) {
1021+
return NULL;
1022+
}
1023+
value = estrdup(tmp);
10181024
#ifdef PHP_WIN32
1019-
if (strlen(sapi_module.name) == sizeof("cgi-fcgi") - 1 && !strcmp(sapi_module.name, "cgi-fcgi")) {
1020-
/* XXX more modules to go, if needed. */
1021-
free(tmp);
1022-
}
1025+
if (strlen(sapi_module.name) == sizeof("cgi-fcgi") - 1 && !strcmp(sapi_module.name, "cgi-fcgi")) {
1026+
/* XXX more modules to go, if needed. */
1027+
free(tmp);
1028+
}
10231029
#endif
1024-
} else {
1025-
return NULL;
1026-
}
1027-
if (sapi_module.input_filter) {
1028-
sapi_module.input_filter(PARSE_STRING, name, &value, strlen(value), NULL);
1029-
}
1030-
return value;
1030+
if (sapi_module.input_filter) {
1031+
sapi_module.input_filter(PARSE_STRING, name, &value, strlen(value), NULL);
10311032
}
1032-
return NULL;
1033+
return value;
10331034
}
10341035

10351036
SAPI_API int sapi_get_fd(int *fd)

0 commit comments

Comments
 (0)