Skip to content
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix double free and null pointer dereference in unusual error scenarios
in :mod:`hashlib` and :mod:`hmac` modules.
4 changes: 2 additions & 2 deletions Modules/hmacmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,6 @@ static void
py_hmac_hinfo_ht_free(void *hinfo)
{
py_hmac_hinfo *entry = (py_hmac_hinfo *)hinfo;
assert(entry->display_name != NULL);
if (--(entry->refcnt) == 0) {
Py_CLEAR(entry->display_name);
PyMem_Free(hinfo);
Expand Down Expand Up @@ -1477,7 +1476,8 @@ py_hmac_hinfo_ht_new(void)
e->hashlib_name == NULL ? e->name : e->hashlib_name
);
if (value->display_name == NULL) {
PyMem_Free(value);
/* 'value' is owned by the table (refcnt > 0),
so _Py_hashtable_destroy() will free it. */
goto error;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Modules/md5module.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ static void
MD5_dealloc(PyObject *op)
{
MD5object *ptr = _MD5object_CAST(op);
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(op);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);
Expand Down
Loading