[3.13] gh-145376: Fix crashes in md5module.c (GH-145422) (#145611)

* gh-145376: Fix crashes in md5module.c

Fix a possible NULL pointer dereference in `md5module.c`.
This can only occur in error paths taken when the interpreter fails to allocate memory.

(cherry-picked from c1d7768321)

* 📜🤖 Added by blurb_it.

* Update Modules/md5module.c

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
Pieter Eendebak 2026-03-06 23:24:20 +01:00 committed by GitHub
parent 16dbbe56f0
commit ae7206eb3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View file

@ -0,0 +1 @@
Fix null pointer dereference in unusual error scenario in :mod:`hashlib`.

View file

@ -84,7 +84,10 @@ MD5_traverse(PyObject *ptr, visitproc visit, void *arg)
static void
MD5_dealloc(MD5object *ptr)
{
Hacl_Hash_MD5_free(ptr->hash_state);
if (ptr->hash_state != NULL) {
Hacl_Hash_MD5_free(ptr->hash_state);
ptr->hash_state = NULL;
}
PyTypeObject *tp = Py_TYPE((PyObject*)ptr);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);