Skip to content

Bug in refactoring in PHP 8.2 Windows shmat() function #9829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TysonAndre opened this issue Oct 25, 2022 · 2 comments
Closed

Bug in refactoring in PHP 8.2 Windows shmat() function #9829

TysonAndre opened this issue Oct 25, 2022 · 2 comments

Comments

@TysonAndre
Copy link
Contributor

TysonAndre commented Oct 25, 2022

Description

The following code:

See krakjoe/apcu#445 for the original report

and #8648

  • The shmat function will now return something other than -1 if the address wasn't allocated, due to checking an offset of a pointer against null instead of checking the original pointer. That seems likely to be the bug affecting windows users of APCu when certain web servers are used on Windows (I'm not familiar with windows APIs)

Resulted in this output:

(apcu (in-memory shared cache) suddenly sharing memory between different php processes in php 8.1.6

But I expected this output instead:

apcu behavior remains the same as php 8.1.5

PHP Version

8.2 and newer

Operating System

Windows

Suggested fix

(I don't have visual studio or Windows to test this with the bug report for apcu_fetch on PHP 8.1.6+ myself, so I don't know if it's already been fixed or can be reproduced by others yet)

--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -690,14 +690,14 @@ TSRM_API void *shmat(int key, const void *shmaddr, int flags)
                return (void*)-1;
        }
 
-       shm->addr = shm->descriptor + sizeof(shm->descriptor);
-
-       if (NULL == shm->addr) {
+       if (NULL == shm->descriptor) {
                int err = GetLastError();
                SET_ERRNO_FROM_WIN32_CODE(err);
                return (void*)-1;
        }
 
+       shm->addr = shm->descriptor + sizeof(shm->descriptor);
@cmb69
Copy link
Member

cmb69 commented Oct 26, 2022

Thanks for reporting! While you are right that this change was not correct, it was only applied to PHP-8.2, so is unlikely the cause of the APCu issue. Anyhow, I'll have a closer look at both.

@TysonAndre
Copy link
Contributor Author

I'm not certain which version it started in, then, my original bug report was inaccurate.

  • They'd upgraded from PHP 7 to PHP 8, so it may be a much older change.
  • I'd only seen this issue yesterday, so I hadn't asked for clarification
  • I don't know if it's part of their ini settings, fpm settings, ini settings, apcu ini settings, etc
  • I still haven't confirmed if it's zts or nts

@TysonAndre TysonAndre changed the title Bug in refactoring in PHP 8.1.6 Windows shmat() function Bug in refactoring in PHP 8.2 Windows shmat() function Nov 1, 2022
cmb69 added a commit to cmb69/php-src that referenced this issue Nov 2, 2022
`shm->addr` cannot be `NULL` here, so the whole check is completely
pointless.
@cmb69 cmb69 linked a pull request Nov 2, 2022 that will close this issue
@cmb69 cmb69 closed this as completed in 1e3915c Nov 2, 2022
cmb69 added a commit that referenced this issue Nov 2, 2022
* PHP-8.2:
  Fix GH-9829: Bug in refactoring Windows shmat() function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants