diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 8d63508d2ab..8f0f39da619 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -514,7 +514,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 00000000000..37cc5c203d2 --- /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-- + +--FILE-- + +--EXPECTF-- +string(%d) "%s" +bool(false) +bool(false) +string(1) "." +string(1) "."