FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-155833: GC-untrack MD5/SHA* objects before freeing the HACL* state (GH-155834) by miss-islington · Pull Request #159789 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (4) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure that MD5 and SHA* objects are properly GC-untracked before freeing
their internal HACL* state. Patch by Bénédikt Tran.
5 changes: 3 additions & 2 deletions Modules/md5module.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ newMD5object(MD5State * st)
return NULL;
}
HASHLIB_INIT_MUTEX(md5);
md5->hash_state = NULL; // PyObject_GC_New() does not zero memory

PyObject_GC_Track(md5);
return md5;
Expand All @@ -86,13 +87,13 @@ newMD5object(MD5State * st)
static void
MD5_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
MD5object *ptr = _MD5object_CAST(op);
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);
Py_DECREF(tp);
}
Expand Down
5 changes: 3 additions & 2 deletions Modules/sha1module.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ newSHA1object(SHA1State *st)
return NULL;
}
HASHLIB_INIT_MUTEX(sha);
sha->hash_state = NULL; // PyObject_GC_New() does not zero memory

PyObject_GC_Track(sha);
return sha;
Expand All @@ -85,13 +86,13 @@ newSHA1object(SHA1State *st)
static void
SHA1_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
SHA1object *ptr = _SHA1object_CAST(op);
if (ptr->hash_state != NULL) {
Hacl_Hash_SHA1_free(ptr->hash_state);
ptr->hash_state = NULL;
}
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);
Py_DECREF(tp);
}
Expand Down
10 changes: 6 additions & 4 deletions Modules/sha2module.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ newSHA384object(sha2_state *state)
return NULL;
}
HASHLIB_INIT_MUTEX(sha);
sha->state = NULL; // PyObject_GC_New() does not zero memory

PyObject_GC_Track(sha);
return sha;
Expand All @@ -159,6 +160,7 @@ newSHA512object(sha2_state *state)
return NULL;
}
HASHLIB_INIT_MUTEX(sha);
sha->state = NULL; // PyObject_GC_New() does not zero memory

PyObject_GC_Track(sha);
return sha;
Expand All @@ -168,27 +170,27 @@ newSHA512object(sha2_state *state)
static void
SHA256_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
SHA256object *ptr = _SHA256object_CAST(op);
if (ptr->state != NULL) {
Hacl_Hash_SHA2_free_256(ptr->state);
ptr->state = NULL;
}
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);
Py_DECREF(tp);
}

static void
SHA512_dealloc(PyObject *op)
{
PyTypeObject *tp = Py_TYPE(op);
PyObject_GC_UnTrack(op);
SHA512object *ptr = _SHA512object_CAST(op);
if (ptr->state != NULL) {
Hacl_Hash_SHA2_free_512(ptr->state);
ptr->state = NULL;
}
PyTypeObject *tp = Py_TYPE(ptr);
PyObject_GC_UnTrack(ptr);
PyObject_GC_Del(ptr);
Py_DECREF(tp);
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/sha3module.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ newSHA3object(PyTypeObject *type)
return NULL;
}
HASHLIB_INIT_MUTEX(newobj);
newobj->hash_state = NULL; // PyObject_GC_New() does not zero memory
newobj->digest_size = newobj->block_size = 0;
PyObject_GC_Track(newobj);
return newobj;
Expand Down Expand Up @@ -234,7 +235,7 @@ SHA3_dealloc(PyObject *self)
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
(void)SHA3_clear(self);
tp->tp_free(self);
PyObject_GC_Del(self);
Py_DECREF(tp);
}

Expand Down
Loading

Back | FazBrowse Home | New Git URL