Skip to content

Fix #81714: segfault when serializing finalized HashContext #8265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions ext/hash/tests/bug81714.phpt
Original file line number Diff line number Diff line change
@@ -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"