Skip to content
Open
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
7 changes: 7 additions & 0 deletions Lib/test/test_hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,13 @@ def test_hmac_digest_digestmod_parameter(self):
):
self.hmac_digest(b'key', b'msg', value)

@support.subTests("xof_name", ("shake_128", "shake_256"))
def test_hmac_new_xof_digestmod(self, xof_name):
# gh-145200: XOF digests (SHAKE) are not supported by HMAC.
# Verify that the error path does not leak the EVP_MAC_CTX.
with self.assertRaises(_hashlib.UnsupportedDigestmodError):
self.hmac_new(b'key', digestmod=xof_name)


class BuiltinConstructorTestCase(ThroughBuiltinAPIMixin,
ExtensionConstructorTestCaseMixin,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`hashlib`: fix a memory leak when allocating
or initializing an OpenSSL HMAC context fails.
1 change: 1 addition & 0 deletions Modules/_hashopenssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ hashlib_HMAC_CTX_new_from_digestmod(_hashlibstate *state,
PY_EVP_MD_free(md);
#endif
if (r == 0) {
hashlib_openssl_HMAC_CTX_free(ctx);
if (is_xof) {
/* use a better default error message if an XOF is used */
raise_unsupported_algorithm_error(state, digestmod);
Expand Down
Loading