Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,11 @@ PHP_FUNCTION(mkdir)
Z_PARAM_RESOURCE_OR_NULL(zcontext)
ZEND_PARSE_PARAMETERS_END();

if (mode < 0 || (mode & ~07777)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to provide a Zend API for this. As a lot of code does file permissions checks (including INI settings (or should at least))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve created a helper function zend_validate_file_permissions(). I think this can be used to validate permission masks for any filesystem-related operations. Please let me know if this approach makes sense.

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));
Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/file/mkdir_invalid_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
mkdir(): invalid mode
--FILE--
<?php
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add few more cases (e.g. -1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

try {
mkdir(__DIR__ . '/testdir', 1000000);
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECT--
mkdir(): Argument #2 ($permissions) must be between 0 and 0o7777
Loading