Skip to content

Commit d8aa7b9

Browse files
committed
ext/standard: pathinfo() check flags argument validity.
1 parent 3d9a0a0 commit d8aa7b9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/standard/string.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,11 @@ PHP_FUNCTION(pathinfo)
15871587
Z_PARAM_LONG(opt)
15881588
ZEND_PARSE_PARAMETERS_END();
15891589

1590+
if (opt < PHP_PATHINFO_DIRNAME || opt > PHP_PATHINFO_ALL) {
1591+
zend_argument_value_error(2, "must be one of the PATHINFO_* constants");
1592+
RETURN_THROWS();
1593+
}
1594+
15901595
have_basename = (opt & PHP_PATHINFO_BASENAME);
15911596

15921597
array_init(&tmp);

ext/standard/tests/strings/pathinfo.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ var_dump(pathinfo(__FILE__, PATHINFO_FILENAME|PATHINFO_BASENAME));
2323
var_dump(pathinfo(__FILE__, PATHINFO_DIRNAME|PATHINFO_EXTENSION));
2424
var_dump(pathinfo(__FILE__, PATHINFO_DIRNAME|PATHINFO_BASENAME));
2525

26+
try {
27+
pathinfo(__FILE__, PATHINFO_DIRNAME-1);
28+
} catch (\ValueError $e) {
29+
echo $e->getMessage(), PHP_EOL;
30+
}
31+
try {
32+
pathinfo(__FILE__, PATHINFO_ALL+1);
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage(), PHP_EOL;
35+
}
36+
2637
echo "Done\n";
2738
?>
2839
--EXPECTF--
@@ -102,4 +113,6 @@ string(%d) "%s%estrings"
102113
string(12) "pathinfo.php"
103114
string(%d) "%s%estrings"
104115
string(%d) "%s%estrings"
116+
pathinfo(): Argument #2 ($flags) must be one of the PATHINFO_* constants
117+
pathinfo(): Argument #2 ($flags) must be one of the PATHINFO_* constants
105118
Done

0 commit comments

Comments
 (0)