Commit 6bd97e72b71 for php.net
commit 6bd97e72b719599b3110fd5ec543b2996f52ba63
Author: arshidkv12 <arshidkv12@gmail.com>
Date: Sat Jan 31 21:14:39 2026 +0530
ext/posix: validate permissions argument in posix_mkfifo()
close GH-21102
diff --git a/NEWS b/NEWS
index b19b09c2144..0872d8dc542 100644
--- a/NEWS
+++ b/NEWS
@@ -80,6 +80,7 @@ PHP NEWS
- Posix:
. Added validity check to the flags argument for posix_access(). (arshidkv12)
+ . Added validity check to the permissions argument for posix_mkfifo(). (arshidkv12)
- Reflection:
. Fixed bug GH-20217 (ReflectionClass::isIterable() incorrectly returns true
diff --git a/ext/posix/posix.c b/ext/posix/posix.c
index 76e14f6ecb0..a81372349fd 100644
--- a/ext/posix/posix.c
+++ b/ext/posix/posix.c
@@ -621,6 +621,11 @@ PHP_FUNCTION(posix_mkfifo)
RETURN_FALSE;
}
+ if (mode < 0 || (mode & ~07777)) {
+ zend_argument_value_error(2, "must be between 0 and 0o7777");
+ RETURN_THROWS();
+ }
+
result = mkfifo(ZSTR_VAL(path), mode);
if (result < 0) {
POSIX_G(last_error) = errno;
diff --git a/ext/posix/tests/posix_mkfifo_invalid_mode.phpt b/ext/posix/tests/posix_mkfifo_invalid_mode.phpt
new file mode 100644
index 00000000000..5c9f251adfc
--- /dev/null
+++ b/ext/posix/tests/posix_mkfifo_invalid_mode.phpt
@@ -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 0o7777
+posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 0o7777
+posix_mkfifo(): Argument #2 ($permissions) must be between 0 and 0o7777