Skip to content

Commit ef59d09

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix handling of open_basedir that contains cwd
2 parents 64918fe + ee7a8ac commit ef59d09

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
CWD on open_basedir should not imply that everything is accessible
3+
--FILE--
4+
<?php
5+
6+
$cwd = getcwd();
7+
ini_set('open_basedir', $cwd);
8+
var_dump(file_get_contents('/some/path/outside/open/basedir'));
9+
10+
?>
11+
--EXPECTF--
12+
Warning: file_get_contents(): open_basedir restriction in effect. File(/some/path/outside/open/basedir) is not within the allowed path(s): (%s) in %s on line %d
13+
14+
Warning: file_get_contents(/some/path/outside/open/basedir): Failed to open stream: Operation not permitted in %s on line %d
15+
bool(false)

main/fopen_wrappers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ PHPAPI int php_check_specific_open_basedir(const char *basedir, const char *path
198198
path_tmp[path_len - 1] = '\0';
199199
#endif
200200
}
201+
if (*path_tmp == '\0') {
202+
/* Do not pass an empty string to realpath(), as this will resolve to CWD. */
203+
break;
204+
}
201205
nesting_level++;
202206
}
203207

0 commit comments

Comments
 (0)