Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ PHP_FUNCTION(posix_mkfifo)
RETURN_FALSE;
}

if (mode < 0 || (mode & ~07777)) {
zend_argument_value_error(
2,
"must be between 0 and 07777"
);
RETURN_THROWS();
}

result = mkfifo(ZSTR_VAL(path), mode);
if (result < 0) {
POSIX_G(last_error) = errno;
Expand Down
36 changes: 36 additions & 0 deletions ext/posix/tests/posix_mkfifo_invalid_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
posix_mkfifo(): invalid mode argument
--SKIPIF--
<?php
if (!function_exists("posix_mkfifo")) {
die("skip no posix_mkfifo()");
}
?>
--FILE--
<?php

// Negative mode
try {
posix_mkfifo(__DIR__ . "/testfifo1", -1);
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

// Too large mode
try {
posix_mkfifo(__DIR__ . "/testfifo2", 010000); // > 07777
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}

// Garbage bits
try {
posix_mkfifo(__DIR__ . "/testfifo3", 020000); // S_IFCHR bit
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 07777
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 07777
posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 07777
Loading