]> granicus.if.org Git - php/commit
SHA-3 Keccak_Hash: Store Keccak_HashInstance in the main context.
authorEddie Kohler <ekohler@gmail.com>
Mon, 22 Jun 2020 03:08:22 +0000 (23:08 -0400)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 30 Jun 2020 12:26:48 +0000 (14:26 +0200)
commit1e9ff7e75743432d0676814561875e73ee259036
treeb08a6fa631e19718524968f3cf4360c9a78326e4
parent815a2be2ed4f39d44b12ef89f24e4baf6ce181d1
SHA-3 Keccak_Hash: Store Keccak_HashInstance in the main context.

Previously, the Keccak_HashInstance was separately allocated.
This could cause memory leaks on errors. For instance,
in php_hash_do_hash_hmac, the following code cleans up after
a file read error:

    if (n < 0) {
     efree(context);
     efree(K);
     zend_string_release(digest);
     RETURN_FALSE;
    }

This does not call the context's hash_final operation, which
was the only way to free the separately-allocated Keccak state.

The simplest fix is simply to place the Keccak_HashInstance state
inside the context object. Then it doesn't need to be freed.

As a result, there is no need to call hash_final in the
HashContext destructor: HashContexts cannot contain internally
allocated resources.
ext/hash/hash.c
ext/hash/hash_sha3.c
ext/hash/php_hash_sha3.h