Skip to content

Commit 4c576a2

Browse files
authored
Fix exception handling in shm_put_var() (#19279)
1 parent ec0ec47 commit 4c576a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ext/sysvshm/sysvshm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ PHP_FUNCTION(shm_put_var)
261261
RETURN_THROWS();
262262
}
263263

264-
ZEND_ASSERT(shm_var.s != NULL);
264+
if (UNEXPECTED(shm_var.s == NULL)) {
265+
RETURN_THROWS();
266+
}
265267

266268
/* insert serialized variable into shared memory */
267269
bool ret = php_put_shm_data(shm_list_ptr->ptr, shm_key, shm_var.s);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
__serialize() exception in shm_put_var()
3+
--EXTENSIONS--
4+
sysvshm
5+
--FILE--
6+
<?php
7+
8+
$key = ftok(__FILE__, 't');
9+
$s = shm_attach($key, 1024);
10+
11+
class Test {
12+
public function __serialize() {
13+
throw new Error("no");
14+
}
15+
}
16+
17+
try {
18+
shm_put_var($s, 1, new Test);
19+
} catch (Error $exception) {
20+
echo $exception->getMessage() . "\n";
21+
}
22+
23+
shm_remove($s);
24+
25+
?>
26+
--EXPECT--
27+
no

0 commit comments

Comments
 (0)