Follow up on bug #75574 for FCGI side

This commit is contained in:
Anatol Belski 2017-11-28 20:31:48 +01:00
parent 2873316d1d
commit 8b57a5bca0
3 changed files with 83 additions and 0 deletions

View file

@ -1027,6 +1027,12 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len)
char *value, *tmp = sapi_module.getenv(name, name_len); char *value, *tmp = sapi_module.getenv(name, name_len);
if (tmp) { if (tmp) {
value = estrdup(tmp); 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
} else { } else {
return NULL; return NULL;
} }

View file

@ -530,9 +530,47 @@ static size_t sapi_fcgi_read_post(char *buffer, size_t count_bytes)
return read_bytes; return read_bytes;
} }
#ifdef PHP_WIN32
/* The result needs to be freed! See sapi_getenv(). */
static char *cgi_getenv_win32(const char *name, size_t name_len)
{
char *ret = NULL;
wchar_t *keyw, *valw;
size_t size;
int rc;
keyw = php_win32_cp_conv_any_to_w(name, name_len, PHP_WIN32_CP_IGNORE_LEN_P);
if (!keyw) {
return NULL;
}
rc = _wgetenv_s(&size, NULL, 0, keyw);
if (rc || 0 == size) {
free(keyw);
return NULL;
}
valw = emalloc((size + 1) * sizeof(wchar_t));
rc = _wgetenv_s(&size, valw, size, keyw);
if (!rc) {
ret = php_win32_cp_w_to_any(valw);
}
free(keyw);
efree(valw);
return ret;
}
#endif
static char *sapi_cgi_getenv(char *name, size_t name_len) static char *sapi_cgi_getenv(char *name, size_t name_len)
{ {
#ifndef PHP_WIN32
return getenv(name); return getenv(name);
#else
return cgi_getenv_win32(name, name_len);
#endif
} }
static char *sapi_fcgi_getenv(char *name, size_t name_len) static char *sapi_fcgi_getenv(char *name, size_t name_len)
@ -547,7 +585,11 @@ static char *sapi_fcgi_getenv(char *name, size_t name_len)
if (ret) return ret; if (ret) return ret;
/* if cgi, or fastcgi and not found in fcgi env /* if cgi, or fastcgi and not found in fcgi env
check the regular environment */ check the regular environment */
#ifndef PHP_WIN32
return getenv(name); return getenv(name);
#else
return cgi_getenv_win32(name, name_len);
#endif
} }
static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value) static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value)

View file

@ -0,0 +1,35 @@
--TEST--
Bug #75574 putenv does not work properly if parameter contains non-ASCII unicode character, UTF-8
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) != 'WIN') {
die("skip Valid only on Windows");
}
include "skipif.inc";
?>
--FILE--
<?php
/*
#vim: set fileencoding=utf-8
#vim: set encoding=utf-8
*/
include "include.inc";
$php = get_cgi_path();
reset_env_vars();
$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . md5(uniqid());
file_put_contents($fn, "<?php\nvar_dump(putenv('FOO=啊'));\n//var_dump(`echo %FOO%`);\nvar_dump(getenv('FOO'));");
echo shell_exec("$php -n -f $fn");
unlink($fn);
?>
===DONE===
--EXPECTF--
bool(true)
string(3) "啊"
===DONE===