]> granicus.if.org Git - php/commitdiff
Fixed bug #72035 php-cgi.exe fails to run scripts relative to drive root
authorAnatol Belski <ab@php.net>
Thu, 21 Apr 2016 19:17:33 +0000 (21:17 +0200)
committerAnatol Belski <ab@php.net>
Sat, 23 Apr 2016 16:55:52 +0000 (18:55 +0200)
ext/standard/tests/file/bug72035.phpt [new file with mode: 0644]
main/fopen_wrappers.c

diff --git a/ext/standard/tests/file/bug72035.phpt b/ext/standard/tests/file/bug72035.phpt
new file mode 100644 (file)
index 0000000..a2abbb7
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Bug #72035 php-cgi.exe fails to run scripts relative to drive root
+--SKIPIF--
+<?php
+if(substr(PHP_OS, 0, 3) != 'WIN' ) die('skip windows only test');
+if(php_sapi_name() != "cli") die('skip CLI only test');
+
+$cgi = realpath(dirname(PHP_BINARY)) . DIRECTORY_SEPARATOR . "php-cgi.exe";
+if (!file_exists($cgi)) die('skip CGI binary not found');
+?>
+--FILE--
+<?php
+
+$fl = dirname(__FILE__) . DIRECTORY_SEPARATOR . md5(uniqid()) . ".php";
+$fl = substr($fl, 2);
+
+$cgi = realpath(dirname(PHP_BINARY) . DIRECTORY_SEPARATOR . "php-cgi.exe");
+
+file_put_contents($fl, "<?php echo \"hello\", \"\n\"; ?>");
+
+$cmd = "$cgi -n -C $fl";
+
+/* Need to run CGI with the env reset. */
+$desc = array(0 => array("pipe", "r"));
+$proc = proc_open($cmd, $desc, $pipes, getcwd(), array());
+if (is_resource($proc)) {
+       echo stream_get_contents($pipes[0]);    
+
+       proc_close($proc);
+}
+
+unlink($fl);
+?>
+==DONE==
+--EXPECTF--
+X-Powered-By: PHP/%s
+Content-type: text/html; charset=UTF-8
+
+hello
+==DONE==
index e4d5688de30ff3e180aaea3e8ecf92b99dcecf49..ab51e5e58bc809194f95feebf525907b4324e3ad 100644 (file)
@@ -505,6 +505,13 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length,
             (IS_SLASH(filename[1]) ||
              ((filename[1] == '.') && IS_SLASH(filename[2])))) ||
            IS_ABSOLUTE_PATH(filename, filename_length) ||
+#if PHP_WIN32
+               /* This should count as an absolute local path as well, however
+                  IS_ABSOLUTE_PATH doesn't care about this path form till now. It
+                  might be a big thing to extend, thus just a local handling for
+                  now. */
+               filename_length >=2 && IS_SLASH(filename[0]) && !IS_SLASH(filename[1]) ||
+#endif
            !path ||
            !*path) {
                if (tsrm_realpath(filename, resolved_path)) {