Skip to content

Commit 000e84a

Browse files
committed
improve fix for CVE-2012-1823
1 parent 2068419 commit 000e84a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sapi/cgi/cgi_main.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,10 +1561,15 @@ int main(int argc, char *argv[])
15611561
}
15621562
}
15631563

1564-
if(query_string = getenv("QUERY_STRING")) {
1564+
if((query_string = getenv("QUERY_STRING")) != NULL && strchr(query_string, '=') == NULL) {
1565+
/* we've got query string that has no = - apache CGI will pass it to command line */
1566+
unsigned char *p;
15651567
decoded_query_string = strdup(query_string);
15661568
php_url_decode(decoded_query_string, strlen(decoded_query_string));
1567-
if(*decoded_query_string == '-' && strchr(decoded_query_string, '=') == NULL) {
1569+
for (p = decoded_query_string; *p && *p <= ' '; p++) {
1570+
/* skip all leading spaces */
1571+
}
1572+
if(*p == '-') {
15681573
skip_getopt = 1;
15691574
}
15701575
free(decoded_query_string);
@@ -1819,7 +1824,7 @@ consult the installation file that came with this distribution, or visit \n\
18191824
}
18201825

18211826
zend_first_try {
1822-
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) {
1827+
while (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) {
18231828
switch (c) {
18241829
case 'T':
18251830
benchmark = 1;

0 commit comments

Comments
 (0)