Skip to content

Commit 5605285

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16591: Assertion error in shm_put_var
2 parents eab17ae + 992ac1c commit 5605285

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ PHP NEWS
117117
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
118118
bail enabled). (ilutov)
119119

120+
- SysVShm:
121+
. Fixed bug GH-16591 (Assertion error in shm_put_var). (nielsdos, cmb)
122+
120123
- XMLReader:
121124
. Fixed bug GH-16292 (Segmentation fault in ext/xmlreader/php_xmlreader.c).
122125
(nielsdos)

ext/sysvshm/sysvshm.c

+6
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ PHP_FUNCTION(shm_put_var)
257257
php_var_serialize(&shm_var, arg_var, &var_hash);
258258
PHP_VAR_SERIALIZE_DESTROY(var_hash);
259259

260+
if (UNEXPECTED(!shm_list_ptr->ptr)) {
261+
smart_str_free(&shm_var);
262+
zend_throw_error(NULL, "Shared memory block has been destroyed by the serialization function");
263+
RETURN_THROWS();
264+
}
265+
260266
/* insert serialized variable into shared memory */
261267
ret = php_put_shm_data(shm_list_ptr->ptr, shm_key, shm_var.s? ZSTR_VAL(shm_var.s) : NULL, shm_var.s? ZSTR_LEN(shm_var.s) : 0);
262268

ext/sysvshm/tests/gh16591.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-16591 (Assertion error in shm_put_var)
3+
--EXTENSIONS--
4+
sysvshm
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
function __serialize(): array {
10+
global $mem;
11+
shm_detach($mem);
12+
return ['a' => 'b'];
13+
}
14+
}
15+
16+
$mem = shm_attach(1);
17+
try {
18+
shm_put_var($mem, 1, new C);
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
23+
?>
24+
--EXPECT--
25+
Shared memory block has been destroyed by the serialization function

0 commit comments

Comments
 (0)