Skip to content

Commit

Permalink
Fix incorrect page_size check
Browse files Browse the repository at this point in the history
The current check always evaluated to false because if `!page_size`
is true, then `page_size & (page_size - 1)` equals `0 & (0 - 1)` which
is always 0. The if condition is meant to check if page_size is zero or
not a power of two, thus we must change the AND to an OR to fix this
issue.

Closes GH-10427

Signed-off-by: George Peter Banyard <girgias@php.net>
  • Loading branch information
nielsdos authored and Girgias committed Jan 25, 2023
1 parent 40da996 commit b7a158a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -9,6 +9,9 @@ PHP NEWS
- FFI:
. Fixed incorrect bitshifting and masking in ffi bitfield. (nielsdos)

- Opcache:
. Fix incorrect page_size check. (nielsdos)

- Standard:
. Fixed bug GH-10292 (Made the default value of the first param of srand() and
mt_srand() unknown). (kocsismate)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.c
Expand Up @@ -3197,7 +3197,7 @@ static zend_result accel_post_startup(void)
size_t page_size;

page_size = zend_get_page_size();
if (!page_size && (page_size & (page_size - 1))) {
if (!page_size || (page_size & (page_size - 1))) {
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Failure to initialize shared memory structures - can't get page size.");
abort();
}
Expand Down

0 comments on commit b7a158a

Please sign in to comment.