Skip to content

Commit 3f0ddb8

Browse files
committed
Fix GH-18281: making flock flags mutually exclusive.
1 parent 1684c52 commit 3f0ddb8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ext/standard/file.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,20 @@ PHP_MSHUTDOWN_FUNCTION(file) /* {{{ */
181181
}
182182
/* }}} */
183183

184+
static inline bool php_is_valid_flock_flag(zend_long s) {
185+
const zend_long sb = s & ~PHP_LOCK_NB;
186+
return (sb == PHP_LOCK_UN || sb == PHP_LOCK_SH ||
187+
sb == PHP_LOCK_EX || s == -1);
188+
}
189+
184190
PHPAPI void php_flock_common(php_stream *stream, zend_long operation,
185191
uint32_t operation_arg_num, zval *wouldblock, zval *return_value)
186192
{
187193
int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
188194
int act;
189195

190196
act = operation & PHP_LOCK_UN;
191-
if (act < 1 || act > 3) {
197+
if (act < 1 || act > 3 || !php_is_valid_flock_flag(operation)) {
192198
zend_argument_value_error(operation_arg_num, "must be one of LOCK_SH, LOCK_EX, or LOCK_UN");
193199
RETURN_THROWS();
194200
}

0 commit comments

Comments
 (0)