Skip to content

Commit 404bed1

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #81407: shmop_open won't attach and causes php to crash
2 parents 805f2b9 + 58ad403 commit 404bed1

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.1.0RC2
44

5+
- Shmop:
6+
. Fixed bug #81407 (shmop_open won't attach and causes php to crash). (cmb)
7+
58
- Opcache:
69
. Fixed bug #81409 (Incorrect JIT code for ADD with a reference to array).
710
(Dmitry)

TSRM/tsrm_win32.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,20 @@ TSRM_API int pclose(FILE *stream)
609609
return termstat;
610610
}/*}}}*/
611611

612+
#define SEGMENT_PREFIX "TSRM_SHM_SEGMENT:"
613+
#define DESCRIPTOR_PREFIX "TSRM_SHM_DESCRIPTOR:"
614+
#define INT_MIN_AS_STRING "-2147483648"
615+
612616
TSRM_API int shmget(key_t key, size_t size, int flags)
613617
{/*{{{*/
614618
shm_pair *shm;
615-
char shm_segment[26], shm_info[29];
619+
char shm_segment[sizeof(SEGMENT_PREFIX INT_MIN_AS_STRING)], shm_info[sizeof(DESCRIPTOR_PREFIX INT_MIN_AS_STRING)];
616620
HANDLE shm_handle = NULL, info_handle = NULL;
617621
BOOL created = FALSE;
618622

619623
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);
624+
snprintf(shm_segment, sizeof(shm_segment), SEGMENT_PREFIX "%d", key);
625+
snprintf(shm_info, sizeof(shm_info), DESCRIPTOR_PREFIX "%d", key);
622626

623627
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
624628
info_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_info);

ext/shmop/tests/bug81407.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #81407 (shmop_open won't attach and causes php to crash)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
6+
if (!extension_loaded("shmop")) die("skip shmop extension not available");
7+
?>
8+
--FILE--
9+
<?php
10+
$a = shmop_open(367504384, 'n', 0664, 262144);
11+
$b = shmop_open(367504385, 'n', 0664, 65536);
12+
if ($b == false) {
13+
$b = shmop_open(367504385, 'w', 0664, 65536);
14+
}
15+
var_dump($a !== false, $b !== false);
16+
?>
17+
--EXPECT--
18+
bool(true)
19+
bool(true)

0 commit comments

Comments
 (0)