Skip to content

Commit e749db4

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79566: Private SHM is not private on Windows
2 parents 901417f + 80b5006 commit e749db4

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

TSRM/tsrm_win32.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,16 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
613613
{/*{{{*/
614614
shm_pair *shm;
615615
char shm_segment[26], shm_info[29];
616-
HANDLE shm_handle, info_handle;
616+
HANDLE shm_handle = NULL, info_handle = NULL;
617617
BOOL created = FALSE;
618618

619-
snprintf(shm_segment, sizeof(shm_segment), "TSRM_SHM_SEGMENT:%d", key);
620-
snprintf(shm_info, sizeof(shm_info), "TSRM_SHM_DESCRIPTOR:%d", key);
619+
if (key != IPC_PRIVATE) {
620+
snprintf(shm_segment, sizeof(shm_segment), "TSRM_SHM_SEGMENT:%d", key);
621+
snprintf(shm_info, sizeof(shm_info), "TSRM_SHM_DESCRIPTOR:%d", key);
621622

622-
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
623-
info_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_info);
623+
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
624+
info_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_info);
625+
}
624626

625627
if (!shm_handle && !info_handle) {
626628
if (flags & IPC_CREAT) {
@@ -631,8 +633,8 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
631633
DWORD high = 0;
632634
DWORD low = size;
633635
#endif
634-
shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, high, low, shm_segment);
635-
info_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(shm->descriptor), shm_info);
636+
shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, high, low, key == IPC_PRIVATE ? NULL : shm_segment);
637+
info_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(shm->descriptor), key == IPC_PRIVATE ? NULL : shm_info);
636638
created = TRUE;
637639
}
638640
if (!shm_handle || !info_handle) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
shmop_open with IPC_PRIVATE creates private SHM
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('shmop')) die('skip shmop extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$write = 'test';
10+
11+
$shm1 = shmop_open(0, 'c', 0777, 1024);
12+
shmop_write($shm1, $write, 0);
13+
14+
$shm2 = shmop_open(0, 'c', 0777, 1024);
15+
$read = shmop_read($shm2, 0, 4);
16+
17+
var_dump(is_string($read) && $read !== $write);
18+
19+
shmop_close($shm1);
20+
shmop_close($shm2);
21+
?>
22+
--EXPECT--
23+
bool(true)

0 commit comments

Comments
 (0)