1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix #81714: segfault when serializing finalized HashContext

We must not allow to serialize already finalized `HashContext`s, since
the internal context is already freed.  Since there is not much point
in serializing finalized `HashContext`s, we just bail out in that case.

Closes GH-8265.
This commit is contained in:
Christoph M. Becker
2022-03-29 11:48:40 +02:00
parent 43f3745abb
commit c2eafc29f5
3 changed files with 20 additions and 0 deletions

3
NEWS
View File

@@ -18,6 +18,9 @@ PHP NEWS
- Filter:
. Fixed signedness confusion in php_filter_validate_domain(). (cmb)
- Hash:
. Fixed bug #81714 (segfault when serializing finalized HashContext). (cmb)
- Intl:
. Fixed bug GH-8142 (Compilation error on cygwin). (David Carlier)

View File

@@ -227,6 +227,9 @@ PHP_HASH_API int php_hash_serialize_spec(const php_hashcontext_object *hash, zva
size_t pos = 0, max_alignment = 1;
unsigned char *buf = (unsigned char *) hash->context;
zval tmp;
if (buf == NULL) {
return FAILURE;
}
array_init(zv);
while (*spec != '\0' && *spec != '.') {
char spec_ch = *spec;

View File

@@ -0,0 +1,14 @@
--TEST--
Bug #81714 (segfault when serializing finalized HashContext)
--FILE--
<?php
$h = hash_init('md5');
hash_final($h);
try {
serialize($h);
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
?>
--EXPECTF--
string(52) "HashContext for algorithm "md5" cannot be serialized"