Skip to content

Commit 29300b1

Browse files
rlerdorfjohannes
authored andcommitted
Fix for CVE-2012-1823
1 parent 704bbb3 commit 29300b1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

sapi/cgi/cgi_main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "php_main.h"
7171
#include "fopen_wrappers.h"
7272
#include "ext/standard/php_standard.h"
73+
#include "ext/standard/url.h"
7374

7475
#ifdef PHP_WIN32
7576
# include <io.h>
@@ -1507,6 +1508,9 @@ int main(int argc, char *argv[])
15071508
#ifndef PHP_WIN32
15081509
int status = 0;
15091510
#endif
1511+
char *query_string;
1512+
char *decoded_query_string;
1513+
int skip_getopt = 0;
15101514

15111515
#if 0 && defined(PHP_DEBUG)
15121516
/* IIS is always making things more difficult. This allows
@@ -1556,7 +1560,16 @@ int main(int argc, char *argv[])
15561560
}
15571561
}
15581562

1559-
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
1563+
if(query_string = getenv("QUERY_STRING")) {
1564+
decoded_query_string = strdup(query_string);
1565+
php_url_decode(decoded_query_string, strlen(decoded_query_string));
1566+
if(*decoded_query_string == '-' && strchr(decoded_query_string, '=') == NULL) {
1567+
skip_getopt = 1;
1568+
}
1569+
free(decoded_query_string);
1570+
}
1571+
1572+
while (!skip_getopt && (c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
15601573
switch (c) {
15611574
case 'c':
15621575
if (cgi_sapi_module.php_ini_path_override) {

0 commit comments

Comments
 (0)