Skip to content

Commit e45a063

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #71542: disk_total_space does not work with relative paths
2 parents 85eafc3 + f924e97 commit e45a063

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
. Fixed bug #81353 (segfault with preloading and statically bound closure).
1212
(Nikita)
1313

14+
- Standard:
15+
. Fixed bug #71542 (disk_total_space does not work with relative paths). (cmb)
16+
1417
- XML:
1518
. Fixed bug #81351 (xml_parse may fail, but has no error code). (cmb, Nikita)
1619

ext/standard/filestat.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,22 @@ static int php_disk_total_space(char *path, double *space) /* {{{ */
176176
PHP_FUNCTION(disk_total_space)
177177
{
178178
double bytestotal;
179-
char *path;
179+
char *path, fullpath[MAXPATHLEN];
180180
size_t path_len;
181181

182182
ZEND_PARSE_PARAMETERS_START(1, 1)
183183
Z_PARAM_PATH(path, path_len)
184184
ZEND_PARSE_PARAMETERS_END();
185185

186-
if (php_check_open_basedir(path)) {
186+
if (!expand_filepath(path, fullpath)) {
187187
RETURN_FALSE;
188188
}
189189

190-
if (php_disk_total_space(path, &bytestotal) == SUCCESS) {
190+
if (php_check_open_basedir(fullpath)) {
191+
RETURN_FALSE;
192+
}
193+
194+
if (php_disk_total_space(fullpath, &bytestotal) == SUCCESS) {
191195
RETURN_DOUBLE(bytestotal);
192196
}
193197
RETURN_FALSE;
@@ -269,18 +273,22 @@ static int php_disk_free_space(char *path, double *space) /* {{{ */
269273
PHP_FUNCTION(disk_free_space)
270274
{
271275
double bytesfree;
272-
char *path;
276+
char *path, fullpath[MAXPATHLEN];
273277
size_t path_len;
274278

275279
ZEND_PARSE_PARAMETERS_START(1, 1)
276280
Z_PARAM_PATH(path, path_len)
277281
ZEND_PARSE_PARAMETERS_END();
278282

279-
if (php_check_open_basedir(path)) {
283+
if (!expand_filepath(path, fullpath)) {
284+
RETURN_FALSE;
285+
}
286+
287+
if (php_check_open_basedir(fullpath)) {
280288
RETURN_FALSE;
281289
}
282290

283-
if (php_disk_free_space(path, &bytesfree) == SUCCESS) {
291+
if (php_disk_free_space(fullpath, &bytesfree) == SUCCESS) {
284292
RETURN_DOUBLE(bytesfree);
285293
}
286294
RETURN_FALSE;

ext/standard/tests/dir/bug71542.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #71542 (disk_total_space does not work with relative paths)
3+
--FILE--
4+
<?php
5+
$dir = basename(getcwd());
6+
chdir("..");
7+
var_dump(
8+
disk_total_space($dir) !== false,
9+
disk_free_space($dir) !== false
10+
);
11+
?>
12+
--EXPECT--
13+
bool(true)
14+
bool(true)

tests/security/open_basedir_disk_free_space.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ bool(true)
2525
bool(true)
2626
bool(true)
2727

28-
Warning: disk_free_space(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d
28+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
2929
bool(false)
3030

31-
Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d
31+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
3232
bool(false)
3333

34-
Warning: disk_free_space(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d
34+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
3535
bool(false)
3636

37-
Warning: disk_free_space(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d
37+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
3838
bool(false)
3939

40-
Warning: disk_free_space(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d
40+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
4141
bool(false)
4242

43-
Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d
43+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
4444
bool(false)
4545

46-
Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d
46+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
4747
bool(false)
4848

49-
Warning: disk_free_space(): open_basedir restriction in effect. File(%s/test/bad/../bad/bad.txt) is not within the allowed path(s): (.) in %s on line %d
49+
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
5050
bool(false)
5151
float(%s)
5252
*** Finished testing open_basedir configuration [disk_free_space] ***

0 commit comments

Comments
 (0)