Skip to content

Commit b501017

Browse files
committed
improve fix for CVE-2012-1823
1 parent 0966406 commit b501017

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
@@ -1807,10 +1807,15 @@ int main(int argc, char *argv[])
18071807
}
18081808
}
18091809

1810-
if(query_string = getenv("QUERY_STRING")) {
1810+
if((query_string = getenv("QUERY_STRING")) != NULL && strchr(query_string, '=') == NULL) {
1811+
/* we've got query string that has no = - apache CGI will pass it to command line */
1812+
unsigned char *p;
18111813
decoded_query_string = strdup(query_string);
18121814
php_url_decode(decoded_query_string, strlen(decoded_query_string));
1813-
if(*decoded_query_string == '-' && strchr(decoded_query_string, '=') == NULL) {
1815+
for (p = decoded_query_string; *p && *p <= ' '; p++) {
1816+
/* skip all leading spaces */
1817+
}
1818+
if(*p == '-') {
18141819
skip_getopt = 1;
18151820
}
18161821
free(decoded_query_string);
@@ -2074,7 +2079,7 @@ consult the installation file that came with this distribution, or visit \n\
20742079
}
20752080

20762081
zend_first_try {
2077-
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) {
2082+
while (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2)) != -1) {
20782083
switch (c) {
20792084
case 'T':
20802085
benchmark = 1;

0 commit comments

Comments
 (0)