Skip to content
Draft
Changes from 1 commit
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: 7 additions & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,20 @@ PHP_MSHUTDOWN_FUNCTION(file) /* {{{ */
}
/* }}} */

static inline bool php_is_valid_flock_flag(zend_long s) {
const zend_long sb = s & ~PHP_LOCK_NB;
return (sb == PHP_LOCK_UN || sb == PHP_LOCK_SH ||
sb == PHP_LOCK_EX || s == -1);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is -1?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems to be an accepted value (a test uses it) even tough it does nothing. I may discard it.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my understanding -1 flag implies all flags set, thus more than 1 exclusive flag set, thus it should not be allowed and hence this PR.

}

PHPAPI void php_flock_common(php_stream *stream, zend_long operation,
uint32_t operation_arg_num, zval *wouldblock, zval *return_value)
{
int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
int act;

act = operation & PHP_LOCK_UN;
if (act < 1 || act > 3) {
if (act < 1 || act > 3 || !php_is_valid_flock_flag(operation)) {
zend_argument_value_error(operation_arg_num, "must be one of LOCK_SH, LOCK_EX, or LOCK_UN");
RETURN_THROWS();
}
Expand Down
Loading