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:
3
NEWS
3
NEWS
@@ -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)
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
14
ext/hash/tests/bug81714.phpt
Normal file
14
ext/hash/tests/bug81714.phpt
Normal 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"
|
||||
Reference in New Issue
Block a user