Skip to content

Commit 6451872

Browse files
committed
Do not call hash_final when destructing a HashContext.
* There is no need any longer, because HashContexts cannot contain internally allocated resources. * It's important not to, in case hash_unserialize produced a bogus context.
1 parent ac607dc commit 6451872

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

ext/hash/hash.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,11 +1357,7 @@ static zend_object* php_hashcontext_create(zend_class_entry *ce) {
13571357
static void php_hashcontext_dtor(zend_object *obj) {
13581358
php_hashcontext_object *hash = php_hashcontext_from_object(obj);
13591359

1360-
/* Just in case the algo has internally allocated resources */
13611360
if (hash->context) {
1362-
unsigned char *dummy = emalloc(hash->ops->digest_size);
1363-
hash->ops->hash_final(dummy, hash->context);
1364-
efree(dummy);
13651361
efree(hash->context);
13661362
hash->context = NULL;
13671363
}
@@ -1528,8 +1524,8 @@ PHP_METHOD(HashContext, __unserialize)
15281524

15291525
unserialize_result = ops->hash_unserialize(hash, magic, hash_zv);
15301526
if (unserialize_result != SUCCESS) {
1531-
zend_value_error("HashContext for algorithm \"%s\" cannot be unserialized, format may be non-portable (code %d)", ops->algo, unserialize_result);
1532-
/* Free internally allocated resources */
1527+
zend_value_error("HashContext for algorithm \"%s\" cannot be unserialized (code %d)", ops->algo, unserialize_result);
1528+
/* free context */
15331529
php_hashcontext_dtor(Z_OBJ_P(object));
15341530
RETURN_THROWS();
15351531
}

0 commit comments

Comments
 (0)