| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Thanks, good catch! Why reorganize the code, though? AFAICS, declaring pointers at the top and setting them to NULL, and an error: block at the end, was deliberate; the style this function was going for is keeping ctx and self non-NULL when they need to be freed. IMO, that's a good way to make complex functions maintainable: repeating a list of currently owned “resources” before each return works for smaller functions, but I think hmac_new is past that size. Not sure about the change from _setException to PyErr_NoMemory -- the OpenSSL docs on HMAC_CTX_new and HMAC_Init_ex aren't explicit on whether it sets an ERR_ error. Are they inconsistent? |
Sorry, something went wrong.
I think it's to align with other instances of similar code. In other cases I think we raise a MemoryError. But I need to check it.
I think the impl comment would be implicit but it's my IDE, I'll restore it. As for r I think I wanted to reduce the kjne length :') I'll just revert this line.
For me it was more an ANSI C approach where all variables are declared at the top of the function. However since I felt it was cleaner like this. But I can revert it and make it ANSI C. |
Sorry, something went wrong.
|
Concerning PyErr_NoMemory, that's what we do in hmac.digest(). NULL is returned by HMAC_CTX_new when allocation fails: https://github.com/openssl/openssl/blob/0bdd10e4078beccaa49ea015b6660f3facfab02b/crypto/hmac/hmac.c#L162. Note that we also return NULL if the context cannot be reset correctly, but this only means that one the underlying EVP contexts couldn't be allocated either: https://github.com/openssl/openssl/blob/0bdd10e4078beccaa49ea015b6660f3facfab02b/crypto/hmac/hmac.c#L198 and https://github.com/openssl/openssl/blob/0bdd10e4078beccaa49ea015b6660f3facfab02b/crypto/evp/digest.c#L129. So the NULL should only be returned by HMAC_CTX_new if either it couldn't be allocated or one of the underlying EVP contexts couldn't be allocated. EDIT: This is assuming we are using openssl implementation for libssl. Any other implementation may not necessarily do the same, but I'm not sure we're actually building against something that is not openssl-compliant. |
Sorry, something went wrong.
…ythonGH-130152) * fix leak in `_hashlib.hmac_new` * fix leak in `hmac_digest` * fix exception type in `_hashlib.HMAC.copy` (cherry picked from commit 0718201) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
GH-130491 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
|
Sorry, @picnixz and @gpshead, I could not cleanly backport this to 3.12 due to a conflict. cherry_picker 071820113f11b8f6a21f98652d0840e10268114c 3.12 |
Sorry, something went wrong.
|
I'll take care of the bp tomorrow (it's 1 AM here) if no one is doing it |
Sorry, something went wrong.
…GH-130152) (#130491) gh-130151: Fix reference leaks in `_hashlib.hmac_{new,digest}` (GH-130152) * fix leak in `_hashlib.hmac_new` * fix leak in `hmac_digest` * fix exception type in `_hashlib.HMAC.copy` (cherry picked from commit 0718201) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
Huh, I forgot. I didn't have time this morning. I'll do it... well, either this night or tomorrow. Sorry :( |
Sorry, something went wrong.
|
GH-130539 is a backport of this pull request to the 3.12 branch. |
Sorry, something went wrong.
…GH-130152) (#130539) gh-130151: Fix reference leaks in `_hashlib.hmac_{new,digest}` (GH-130152) * fix leak in `_hashlib.hmac_new` * fix leak in `hmac_digest` * fix exception type in `_hashlib.HMAC.copy` (cherry picked from commit 0718201)
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.