Skip to content

Commit 945ac59

Browse files
committed
Fix phpGH-18281: making flock flags mutually exclusive.
proposing a standard way to detect bitwise values through a new Zend entry.
1 parent 1684c52 commit 945ac59

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: Zend/zend_portability.h

+16
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,22 @@ char *alloca();
403403
# define JMP_BUF jmp_buf
404404
#endif
405405

406+
#ifdef ZEND_ENABLE_ZVAL_LONG64
407+
# ifdef _MSC_VER
408+
# define ZEND_POPCOUNT(x) _popcnt64(x)
409+
# else
410+
# define ZEND_POPCOUNT(x) __builtin_popcountll(x)
411+
# endif
412+
#else
413+
# ifdef _MSC_VER
414+
# define ZEND_POPCOUNT(x) _popcnt(x)
415+
# else
416+
# define ZEND_POPCOUNT(x) __builtin_popcount(x)
417+
# endif
418+
#endif
419+
420+
#define ZEND_ISBITWISE(x) (ZEND_POPCOUNT(x) > 1)
421+
406422
#if ZEND_DEBUG
407423
# define ZEND_FILE_LINE_D const char *__zend_filename, const uint32_t __zend_lineno
408424
# define ZEND_FILE_LINE_DC , ZEND_FILE_LINE_D

Diff for: ext/standard/file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ PHPAPI void php_flock_common(php_stream *stream, zend_long operation,
188188
int act;
189189

190190
act = operation & PHP_LOCK_UN;
191-
if (act < 1 || act > 3) {
191+
if (act < 1 || act > 3 || ZEND_ISBITWISE(act)) {
192192
zend_argument_value_error(operation_arg_num, "must be one of LOCK_SH, LOCK_EX, or LOCK_UN");
193193
RETURN_THROWS();
194194
}

0 commit comments

Comments
 (0)