mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #71542: disk_total_space does not work with relative paths
This commit is contained in:
commit
02b725a269
3 changed files with 36 additions and 14 deletions
|
@ -176,18 +176,22 @@ static int php_disk_total_space(char *path, double *space) /* {{{ */
|
|||
PHP_FUNCTION(disk_total_space)
|
||||
{
|
||||
double bytestotal;
|
||||
char *path;
|
||||
char *path, fullpath[MAXPATHLEN];
|
||||
size_t path_len;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_PATH(path, path_len)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (php_check_open_basedir(path)) {
|
||||
if (!expand_filepath(path, fullpath)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (php_disk_total_space(path, &bytestotal) == SUCCESS) {
|
||||
if (php_check_open_basedir(fullpath)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (php_disk_total_space(fullpath, &bytestotal) == SUCCESS) {
|
||||
RETURN_DOUBLE(bytestotal);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
|
@ -269,18 +273,22 @@ static int php_disk_free_space(char *path, double *space) /* {{{ */
|
|||
PHP_FUNCTION(disk_free_space)
|
||||
{
|
||||
double bytesfree;
|
||||
char *path;
|
||||
char *path, fullpath[MAXPATHLEN];
|
||||
size_t path_len;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(1, 1)
|
||||
Z_PARAM_PATH(path, path_len)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (php_check_open_basedir(path)) {
|
||||
if (!expand_filepath(path, fullpath)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (php_disk_free_space(path, &bytesfree) == SUCCESS) {
|
||||
if (php_check_open_basedir(fullpath)) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (php_disk_free_space(fullpath, &bytesfree) == SUCCESS) {
|
||||
RETURN_DOUBLE(bytesfree);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
|
|
14
ext/standard/tests/dir/bug71542.phpt
Normal file
14
ext/standard/tests/dir/bug71542.phpt
Normal file
|
@ -0,0 +1,14 @@
|
|||
--TEST--
|
||||
Bug #71542 (disk_total_space does not work with relative paths)
|
||||
--FILE--
|
||||
<?php
|
||||
$dir = basename(getcwd());
|
||||
chdir("..");
|
||||
var_dump(
|
||||
disk_total_space($dir) !== false,
|
||||
disk_free_space($dir) !== false
|
||||
);
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(true)
|
|
@ -25,28 +25,28 @@ bool(true)
|
|||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(../bad) is not within the allowed path(s): (.) in %s on line %d
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
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
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(..) is not within the allowed path(s): (.) in %s on line %d
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(../) is not within the allowed path(s): (.) in %s on line %d
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (.) in %s on line %d
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(../bad/.) is not within the allowed path(s): (.) in %s on line %d
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
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
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
|
||||
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
|
||||
Warning: disk_free_space(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (.) in %s on line %d
|
||||
bool(false)
|
||||
float(%s)
|
||||
*** Finished testing open_basedir configuration [disk_free_space] ***
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue