Skip to content

Commit

Permalink
posix_pathconf throwing ValueError on empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored and Girgias committed Jan 10, 2023
1 parent ecc880f commit 61cf7d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ext/posix/posix.c
Expand Up @@ -1208,7 +1208,11 @@ PHP_FUNCTION(posix_pathconf)
Z_PARAM_LONG(name);
ZEND_PARSE_PARAMETERS_END();

if (path_len == 0 || php_check_open_basedir(path)) {
if (path_len == 0) {
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
} else if (php_check_open_basedir(path)) {
php_error_docref(NULL, E_WARNING, "Invalid path supplied: %s", path);
RETURN_FALSE;
}

Expand Down
8 changes: 6 additions & 2 deletions ext/posix/tests/posix_pathconf.phpt
Expand Up @@ -4,13 +4,17 @@ Test posix_pathconf
posix
--FILE--
<?php
var_dump(posix_pathconf('', POSIX_PC_PATH_MAX));
try {
posix_pathconf('', POSIX_PC_PATH_MAX);
} catch (\ValueError $e) {
echo $e->getMessage(). "\n";
}
var_dump(posix_pathconf(str_repeat('non_existent', 4096), POSIX_PC_NAME_MAX));
var_dump(posix_errno() != 0);
var_dump(posix_pathconf(sys_get_temp_dir(), POSIX_PC_PATH_MAX));
?>
--EXPECTF--
bool(false)
posix_pathconf(): Argument #1 ($path) cannot be empty
bool(false)
bool(true)
int(%d)

0 comments on commit 61cf7d4

Please sign in to comment.