Skip to content

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

Closed
@TysonAndre

Description

@TysonAndre

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);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions