Skip to content

Commit 0b30461

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Follow up on bug #75574 for FCGI side
2 parents 7c043ff + 8b57a5b commit 0b30461

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

main/SAPI.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,12 @@ SAPI_API char *sapi_getenv(char *name, size_t name_len)
10271027
char *value, *tmp = sapi_module.getenv(name, name_len);
10281028
if (tmp) {
10291029
value = estrdup(tmp);
1030+
#ifdef PHP_WIN32
1031+
if (strlen(sapi_module.name) == sizeof("cgi-fcgi") - 1 && !strcmp(sapi_module.name, "cgi-fcgi")) {
1032+
/* XXX more modules to go, if needed. */
1033+
free(tmp);
1034+
}
1035+
#endif
10301036
} else {
10311037
return NULL;
10321038
}

sapi/cgi/cgi_main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,47 @@ static size_t sapi_fcgi_read_post(char *buffer, size_t count_bytes)
534534
return read_bytes;
535535
}
536536

537+
#ifdef PHP_WIN32
538+
/* The result needs to be freed! See sapi_getenv(). */
539+
static char *cgi_getenv_win32(const char *name, size_t name_len)
540+
{
541+
char *ret = NULL;
542+
wchar_t *keyw, *valw;
543+
size_t size;
544+
int rc;
545+
546+
keyw = php_win32_cp_conv_any_to_w(name, name_len, PHP_WIN32_CP_IGNORE_LEN_P);
547+
if (!keyw) {
548+
return NULL;
549+
}
550+
551+
rc = _wgetenv_s(&size, NULL, 0, keyw);
552+
if (rc || 0 == size) {
553+
free(keyw);
554+
return NULL;
555+
}
556+
557+
valw = emalloc((size + 1) * sizeof(wchar_t));
558+
559+
rc = _wgetenv_s(&size, valw, size, keyw);
560+
if (!rc) {
561+
ret = php_win32_cp_w_to_any(valw);
562+
}
563+
564+
free(keyw);
565+
efree(valw);
566+
567+
return ret;
568+
}
569+
#endif
570+
537571
static char *sapi_cgi_getenv(char *name, size_t name_len)
538572
{
573+
#ifndef PHP_WIN32
539574
return getenv(name);
575+
#else
576+
return cgi_getenv_win32(name, name_len);
577+
#endif
540578
}
541579

542580
static char *sapi_fcgi_getenv(char *name, size_t name_len)
@@ -551,7 +589,11 @@ static char *sapi_fcgi_getenv(char *name, size_t name_len)
551589
if (ret) return ret;
552590
/* if cgi, or fastcgi and not found in fcgi env
553591
check the regular environment */
592+
#ifndef PHP_WIN32
554593
return getenv(name);
594+
#else
595+
return cgi_getenv_win32(name, name_len);
596+
#endif
555597
}
556598

557599
static char *_sapi_cgi_putenv(char *name, size_t name_len, char *value)

sapi/cgi/tests/bug75574_utf8_win.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #75574 putenv does not work properly if parameter contains non-ASCII unicode character, UTF-8
3+
--SKIPIF--
4+
<?php
5+
6+
if (substr(PHP_OS, 0, 3) != 'WIN') {
7+
die("skip Valid only on Windows");
8+
}
9+
include "skipif.inc";
10+
?>
11+
--FILE--
12+
<?php
13+
/*
14+
#vim: set fileencoding=utf-8
15+
#vim: set encoding=utf-8
16+
*/
17+
18+
include "include.inc";
19+
20+
$php = get_cgi_path();
21+
reset_env_vars();
22+
23+
$fn = dirname(__FILE__) . DIRECTORY_SEPARATOR . md5(uniqid());
24+
file_put_contents($fn, "<?php\nvar_dump(putenv('FOO=啊'));\n//var_dump(`echo %FOO%`);\nvar_dump(getenv('FOO'));");
25+
26+
echo shell_exec("$php -n -f $fn");
27+
28+
unlink($fn);
29+
30+
?>
31+
===DONE===
32+
--EXPECTF--
33+
bool(true)
34+
string(3) "啊"
35+
===DONE===

0 commit comments

Comments
 (0)