Skip to content

Commit 80b5006

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79566: Private SHM is not private on Windows
2 parents ed6bf0b + f33cf52 commit 80b5006

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.4.7
44

5+
- Core:
6+
. Fixed bug #79566 (Private SHM is not private on Windows). (cmb)
7+
58
- SimpleXML:
69
. Fixed bug #79528 (Different object of the same xml between 7.4.5 and
710
7.4.4). (cmb)

TSRM/tsrm_win32.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,16 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
615615
{/*{{{*/
616616
shm_pair *shm;
617617
char shm_segment[26], shm_info[29];
618-
HANDLE shm_handle, info_handle;
618+
HANDLE shm_handle = NULL, info_handle = NULL;
619619
BOOL created = FALSE;
620620

621-
snprintf(shm_segment, sizeof(shm_segment), "TSRM_SHM_SEGMENT:%d", key);
622-
snprintf(shm_info, sizeof(shm_info), "TSRM_SHM_DESCRIPTOR:%d", key);
621+
if (key != IPC_PRIVATE) {
622+
snprintf(shm_segment, sizeof(shm_segment), "TSRM_SHM_SEGMENT:%d", key);
623+
snprintf(shm_info, sizeof(shm_info), "TSRM_SHM_DESCRIPTOR:%d", key);
623624

624-
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
625-
info_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_info);
625+
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
626+
info_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_info);
627+
}
626628

627629
if (!shm_handle && !info_handle) {
628630
if (flags & IPC_CREAT) {
@@ -633,8 +635,8 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
633635
DWORD high = 0;
634636
DWORD low = size;
635637
#endif
636-
shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, high, low, shm_segment);
637-
info_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(shm->descriptor), shm_info);
638+
shm_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, high, low, key == IPC_PRIVATE ? NULL : shm_segment);
639+
info_handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(shm->descriptor), key == IPC_PRIVATE ? NULL : shm_info);
638640
created = TRUE;
639641
}
640642
if (!shm_handle || !info_handle) {
+23
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)