Fix exception handling in shm_put_var() (#19279)

This commit is contained in:
Niels Dossche 2025-07-29 17:31:06 +02:00 committed by GitHub
parent ec0ec47bbf
commit 4c576a2b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View file

@ -261,7 +261,9 @@ PHP_FUNCTION(shm_put_var)
RETURN_THROWS();
}
ZEND_ASSERT(shm_var.s != NULL);
if (UNEXPECTED(shm_var.s == NULL)) {
RETURN_THROWS();
}
/* insert serialized variable into shared memory */
bool ret = php_put_shm_data(shm_list_ptr->ptr, shm_key, shm_var.s);

View file

@ -0,0 +1,27 @@
--TEST--
__serialize() exception in shm_put_var()
--EXTENSIONS--
sysvshm
--FILE--
<?php
$key = ftok(__FILE__, 't');
$s = shm_attach($key, 1024);
class Test {
public function __serialize() {
throw new Error("no");
}
}
try {
shm_put_var($s, 1, new Test);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
shm_remove($s);
?>
--EXPECT--
no