Skip to content

Commit 6bd97e7

Browse files
arshidkv12devnexen
authored andcommitted
ext/posix: validate permissions argument in posix_mkfifo()
close phpGH-21102
1 parent d3e4703 commit 6bd97e7

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ PHP NEWS
8080

8181
- Posix:
8282
. Added validity check to the flags argument for posix_access(). (arshidkv12)
83+
. Added validity check to the permissions argument for posix_mkfifo(). (arshidkv12)
8384

8485
- Reflection:
8586
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true

ext/posix/posix.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ PHP_FUNCTION(posix_mkfifo)
621621
RETURN_FALSE;
622622
}
623623

624+
if (mode < 0 || (mode & ~07777)) {
625+
zend_argument_value_error(2, "must be between 0 and 0o7777");
626+
RETURN_THROWS();
627+
}
628+
624629
result = mkfifo(ZSTR_VAL(path), mode);
625630
if (result < 0) {
626631
POSIX_G(last_error) = errno;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
posix_mkfifo(): invalid mode argument
3+
--SKIPIF--
4+
<?php
5+
if (!function_exists("posix_mkfifo")) {
6+
die("skip no posix_mkfifo()");
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
12+
// Negative mode
13+
try {
14+
posix_mkfifo(__DIR__ . "/testfifo1", -1);
15+
} catch (ValueError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
19+
// Too large mode
20+
try {
21+
posix_mkfifo(__DIR__ . "/testfifo2", 010000); // > 07777
22+
} catch (ValueError $e) {
23+
echo $e->getMessage(), "\n";
24+
}
25+
26+
// Garbage bits
27+
try {
28+
posix_mkfifo(__DIR__ . "/testfifo3", 020000); // S_IFCHR bit
29+
} catch (ValueError $e) {
30+
echo $e->getMessage(), "\n";
31+
}
32+
?>
33+
--EXPECTF--
34+
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 0o7777
35+
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 0o7777
36+
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 0o7777

0 commit comments

Comments
 (0)