Skip to content

Commit b28e7e4

Browse files
committed
ext/standard: Throw ValueError for filenames with null bytes
This should never happen in the first place
1 parent 2568744 commit b28e7e4

20 files changed

+136
-108
lines changed

ext/standard/filestat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ ZEND_NAMED_FUNCTION(name) { \
10141014
zend_string *filename; \
10151015
\
10161016
ZEND_PARSE_PARAMETERS_START(1, 1) \
1017-
Z_PARAM_STR(filename) \
1017+
Z_PARAM_PATH_STR(filename) \
10181018
ZEND_PARSE_PARAMETERS_END(); \
10191019
\
10201020
php_stat(filename, funcnum, return_value); \

ext/standard/tests/file/bug39863.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ Andrew van der Stock, vanderaj @ owasp.org
66
<?php
77

88
$filename = __FILE__ . chr(0). ".ridiculous";
9-
var_dump(file_exists($filename));
9+
try {
10+
var_dump(file_exists($filename));
11+
} catch (Throwable $e) {
12+
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
13+
}
1014
?>
1115
--EXPECT--
12-
bool(false)
16+
ValueError: file_exists(): Argument #1 ($filename) must not contain any null bytes
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
filegroup() with filenames with null bytes
3+
--FILE--
4+
<?php
5+
6+
try {
7+
var_dump(filegroup("file_with_null_byte.tmp\0"));
8+
} catch (Throwable $e) {
9+
echo $e::class, ': ', $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
ValueError: filegroup(): Argument #1 ($filename) must not contain any null bytes

ext/standard/tests/file/filegroup_variation3.phpt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ $files_arr = array(
2626
"//filegroup_variation3//filegroup_variation3.tmp",
2727
"/filegroup_variation3/*.tmp",
2828
"filegroup_variation3/filegroup*.tmp",
29-
30-
/* Testing Binary safe */
31-
"/filegroup_variation3/filegroup_variation3.tmp".chr(0),
32-
"/filegroup_variation3/filegroup_variation3.tmp\0"
3329
);
3430

3531
$count = 1;
@@ -74,13 +70,5 @@ bool(false)
7470

7571
Warning: filegroup(): stat failed for %s/filegroup_variation3/filegroup*.tmp in %s on line %d
7672
bool(false)
77-
- Iteration 7 -
78-
79-
Warning: filegroup(): Filename contains null byte in %s on line %d
80-
bool(false)
81-
- Iteration 8 -
82-
83-
Warning: filegroup(): Filename contains null byte in %s on line %d
84-
bool(false)
8573

8674
*** Done ***
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
fileinode() with filenames with null bytes
3+
--FILE--
4+
<?php
5+
6+
try {
7+
var_dump(fileinode("file_with_null_byte.tmp\0"));
8+
} catch (Throwable $e) {
9+
echo $e::class, ': ', $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
ValueError: fileinode(): Argument #1 ($filename) must not contain any null bytes

ext/standard/tests/file/fileinode_variation3.phpt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ $files_arr = array(
2525
"//fileinode_variation3//fileinode_variation3.tmp",
2626
"/fileinode_variation3/*.tmp",
2727
"fileinode_variation3/fileinode*.tmp",
28-
29-
/* Testing Binary safe */
30-
"/fileinode_variation3/fileinode_variation3.tmp".chr(0),
31-
"/fileinode_variation3/fileinode_variation3.tmp\0"
3228
);
3329

3430
$count = 1;
@@ -73,13 +69,5 @@ bool(false)
7369

7470
Warning: fileinode(): stat failed for %s/fileinode_variation3/fileinode*.tmp in %s on line %d
7571
bool(false)
76-
- Iteration 7 -
77-
78-
Warning: fileinode(): Filename contains null byte in %s on line %d
79-
bool(false)
80-
- Iteration 8 -
81-
82-
Warning: fileinode(): Filename contains null byte in %s on line %d
83-
bool(false)
8472

8573
*** Done ***
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
fileowner() with filenames with null bytes
3+
--FILE--
4+
<?php
5+
6+
try {
7+
var_dump(fileowner("file_with_null_byte.tmp\0"));
8+
} catch (Throwable $e) {
9+
echo $e::class, ': ', $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
ValueError: fileowner(): Argument #1 ($filename) must not contain any null bytes

ext/standard/tests/file/fileowner_variation3.phpt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ $files_arr = array(
2626
"//fileowner_variation3//fileowner_variation3.tmp",
2727
"/fileowner_variation3/*.tmp",
2828
"fileowner_variation3/fileowner*.tmp",
29-
30-
/* Testing Binary safe */
31-
"/fileowner_variation3/fileowner_variation3.tmp".chr(0),
32-
"/fileowner_variation3/fileowner_variation3.tmp\0"
3329
);
3430

3531
$count = 1;
@@ -74,13 +70,5 @@ bool(false)
7470

7571
Warning: fileowner(): stat failed for %s/fileowner_variation3/fileowner*.tmp in %s on line %d
7672
bool(false)
77-
- Iteration 7 -
78-
79-
Warning: fileowner(): Filename contains null byte in %s on line %d
80-
bool(false)
81-
- Iteration 8 -
82-
83-
Warning: fileowner(): Filename contains null byte in %s on line %d
84-
bool(false)
8573

8674
*** Done ***
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
fileperms() with filenames with null bytes
3+
--FILE--
4+
<?php
5+
6+
try {
7+
var_dump(fileperms("file_with_null_byte.tmp\0"));
8+
} catch (Throwable $e) {
9+
echo $e::class, ': ', $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
ValueError: fileperms(): Argument #1 ($filename) must not contain any null bytes

ext/standard/tests/file/fileperms_variation3.phpt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ $files_arr = array(
2525
"//fileperms_variation3//fileperms_variation3.tmp",
2626
"/fileperms_variation3/*.tmp",
2727
"fileperms_variation3/fileperms*.tmp",
28-
29-
/* Testing Binary safe */
30-
"/fileperms_variation3/fileperms_variation3.tmp".chr(0),
31-
"/fileperms_variation3/fileperms_variation3.tmp\0"
3228
);
3329

3430
$count = 1;
@@ -73,13 +69,5 @@ bool(false)
7369

7470
Warning: fileperms(): stat failed for %s/fileperms_variation3/fileperms*.tmp in %s on line %d
7571
bool(false)
76-
- Iteration 7 -
77-
78-
Warning: fileperms(): Filename contains null byte in %s on line %d
79-
bool(false)
80-
- Iteration 8 -
81-
82-
Warning: fileperms(): Filename contains null byte in %s on line %d
83-
bool(false)
8472

8573
*** Done ***

0 commit comments

Comments
 (0)