Skip to content

Commit 58ad403

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #81407: shmop_open won't attach and causes php to crash
2 parents fde24e4 + f3d24af commit 58ad403

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
@@ -16,6 +16,9 @@ PHP NEWS
1616
. Fixed bug #81353 (segfault with preloading and statically bound closure).
1717
(Nikita)
1818

19+
- Shmop:
20+
. Fixed bug #81407 (shmop_open won't attach and causes php to crash). (cmb)
21+
1922
- Standard:
2023
. Fixed bug #71542 (disk_total_space does not work with relative paths). (cmb)
2124
. Fixed bug #81400 (Unterminated string in dns_get_record() results). (cmb)

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)