Skip to content

Commit 12d8be7

Browse files
committed
ext/standard: validate mode is within 0..07777
1 parent d3e4703 commit 12d8be7

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

ext/standard/file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,11 @@ PHP_FUNCTION(mkdir)
10871087
Z_PARAM_RESOURCE_OR_NULL(zcontext)
10881088
ZEND_PARSE_PARAMETERS_END();
10891089

1090+
if (mode < 0 || (mode & ~07777)) {
1091+
zend_argument_value_error(2, "must be between 0 and 0o7777");
1092+
RETURN_THROWS();
1093+
}
1094+
10901095
context = php_stream_context_from_zval(zcontext, 0);
10911096

10921097
RETURN_BOOL(php_stream_mkdir(dir, (int)mode, (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
mkdir(): invalid mode
3+
--FILE--
4+
<?php
5+
try {
6+
mkdir(__DIR__ . '/testdir', 1000000);
7+
} catch (ValueError $e) {
8+
echo $e->getMessage(), PHP_EOL;
9+
}
10+
?>
11+
--EXPECT--
12+
mkdir(): Argument #2 ($permissions) must be between 0 and 0o7777

0 commit comments

Comments
 (0)