Skip to content

Commit 187f5a3

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #81714: segfault when serializing finalized HashContext
2 parents 2b4fee0 + c2eafc2 commit 187f5a3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
. Fixed bug GH-8289 (Exceptions thrown within a yielded from iterator are
1212
not rethrown into the generator). (Bob)
1313

14+
- Hash:
15+
. Fixed bug #81714 (segfault when serializing finalized HashContext). (cmb)
16+
1417
31 Mar 2022, PHP 8.1.5
1518

1619
- Core:

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)