diff --git a/ext/standard/file.c b/ext/standard/file.c index a7b73f1fe56eb..ca24b34eb8c4f 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1087,6 +1087,11 @@ PHP_FUNCTION(mkdir) Z_PARAM_RESOURCE_OR_NULL(zcontext) ZEND_PARSE_PARAMETERS_END(); + if (mode < 0 || (mode & ~07777)) { + zend_argument_value_error(2, "must be between 0 and 0o7777"); + RETURN_THROWS(); + } + context = php_stream_context_from_zval(zcontext, 0); RETURN_BOOL(php_stream_mkdir(dir, (int)mode, (recursive ? PHP_STREAM_MKDIR_RECURSIVE : 0) | REPORT_ERRORS, context)); diff --git a/ext/standard/tests/file/mkdir_invalid_mode.phpt b/ext/standard/tests/file/mkdir_invalid_mode.phpt new file mode 100644 index 0000000000000..b45ad204cb3e1 --- /dev/null +++ b/ext/standard/tests/file/mkdir_invalid_mode.phpt @@ -0,0 +1,12 @@ +--TEST-- +mkdir(): invalid mode +--FILE-- +getMessage(), PHP_EOL; +} +?> +--EXPECT-- +mkdir(): Argument #2 ($permissions) must be between 0 and 0o7777