1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-14537: shmop Windows 11 crashes the process

The error handling code isn't entirely right in two places.
One of the code blocks is dead because of an always-false condition, and
another code block is missing the assignment of a NULL pointer.

Getting the exact same behaviour is not entirely possible because you
can't extend the size of a shared memory region after it was made with
the Windows APIs we use, unless we destroy the region and recreate it,
but that has other consequences.
However, it certainly shouldn't crash.

Closes GH-14707.
This commit is contained in:
Niels Dossche
2024-06-28 18:26:47 +02:00
parent 5a32b510ef
commit 39a3266576
3 changed files with 32 additions and 2 deletions

View File

@@ -709,6 +709,7 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
CloseHandle(shm->segment);
}
UnmapViewOfFile(shm->descriptor);
shm->descriptor = NULL;
return -1;
}
@@ -744,8 +745,8 @@ TSRM_API int shmdt(const void *shmaddr)
shm->descriptor->shm_lpid = getpid();
shm->descriptor->shm_nattch--;
ret = 1;
if (!ret && shm->descriptor->shm_nattch <= 0) {
ret = 0;
if (shm->descriptor->shm_nattch <= 0) {
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
shm->descriptor = NULL;
}