diff options
author | Anatol Belski <ab@php.net> | 2019-01-19 02:34:59 +0100 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2019-01-19 02:36:51 +0100 |
commit | 8b20e7b68bd81ab74423c9f7937699f79401cec4 (patch) | |
tree | aa4810d87893eaf3d1ab6dde50a8800e8d1fceba | |
parent | 986b9b5ae3e04e33fda89f102da1bba625aa06ef (diff) | |
download | php-git-8b20e7b68bd81ab74423c9f7937699f79401cec4.tar.gz |
Fixed bug #77484 Zend engine crashes when calling realpath in invalid working dir
-rw-r--r-- | Zend/zend_virtual_cwd.c | 2 | ||||
-rw-r--r-- | ext/standard/tests/file/realpath_bug77484.phpt | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index d26aec9148..8a41cfc343 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -764,7 +764,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim if (i == len || (i + 1 == len && path[i] == '.')) { /* remove double slashes and '.' */ - len = i - 1; + len = EXPECTED(i > 0) ? i - 1 : 0; is_dir = 1; continue; } else if (i + 2 == len && path[i] == '.' && path[i+1] == '.') { diff --git a/ext/standard/tests/file/realpath_bug77484.phpt b/ext/standard/tests/file/realpath_bug77484.phpt new file mode 100644 index 0000000000..37cc5c203d --- /dev/null +++ b/ext/standard/tests/file/realpath_bug77484.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #77484 Zend engine crashes when calling realpath in invalid working dir +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip can't remove CWD on Windows"); +} +?> +--FILE-- +<?php + +var_dump(\getcwd()); + +\mkdir(__DIR__ . "/foo"); +\chdir(__DIR__ . "/foo"); +\rmdir(__DIR__ . "/foo"); + +// Outputs: / (incorrect) +var_dump(\getcwd()); + +// Outputs: false (correct) +var_dump(\realpath('')); + +// Crash +var_dump(\realpath('.'), \realpath('./')); + +?> +--EXPECTF-- +string(%d) "%s" +bool(false) +bool(false) +string(1) "." +string(1) "." |