Skip to content

Commit 012ef79

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix #81714: segfault when serializing finalized HashContext
2 parents ee34c29 + 187f5a3 commit 012ef79

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/hash/hash.c

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ PHP_HASH_API int php_hash_serialize_spec(const php_hashcontext_object *hash, zva
234234
size_t pos = 0, max_alignment = 1;
235235
unsigned char *buf = (unsigned char *) hash->context;
236236
zval tmp;
237+
if (buf == NULL) {
238+
return FAILURE;
239+
}
237240
array_init(zv);
238241
while (*spec != '\0' && *spec != '.') {
239242
char spec_ch = *spec;

ext/hash/tests/bug81714.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #81714 (segfault when serializing finalized HashContext)
3+
--FILE--
4+
<?php
5+
$h = hash_init('md5');
6+
hash_final($h);
7+
try {
8+
serialize($h);
9+
} catch (Exception $ex) {
10+
var_dump($ex->getMessage());
11+
}
12+
?>
13+
--EXPECTF--
14+
string(52) "HashContext for algorithm "md5" cannot be serialized"

0 commit comments

Comments
 (0)