Skip to content

gh-145200: Fix EVP_MAC_CTX leak in hashlib HMAC on init failure#145201

Merged
gpshead merged 5 commits intopython:mainfrom
raminfp:fix-gh-145200-hashlib-hmac-ctx-leak
Apr 11, 2026
Merged

gh-145200: Fix EVP_MAC_CTX leak in hashlib HMAC on init failure#145201
gpshead merged 5 commits intopython:mainfrom
raminfp:fix-gh-145200-hashlib-hmac-ctx-leak

Conversation

@raminfp
Copy link
Copy Markdown
Contributor

@raminfp raminfp commented Feb 25, 2026

Free the EVP_MAC_CTX (or HMAC_CTX) when EVP_MAC_init() (or HMAC_Init_ex()) fails in hashlib_HMAC_CTX_new_from_digestmod(), preventing a memory leak on every failed call.

Comment thread Misc/NEWS.d/next/Library/2026-02-25-10-00-00.gh-issue-145200.m_4PAtcI.rst Outdated
Comment thread Lib/test/test_hmac.py Outdated
raminfp and others added 2 commits February 25, 2026 12:16
…_4PAtcI.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@raminfp raminfp requested a review from picnixz February 25, 2026 08:47
Comment thread Misc/NEWS.d/next/Library/2026-02-25-10-00-00.gh-issue-145200.m_4PAtcI.rst Outdated
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor doc tweak.

…_4PAtcI.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Feb 25, 2026

I'm going to run the refleak bots just in case so don't commit anything until the tests are done, TiA!

@picnixz picnixz added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 25, 2026
@bedevere-bot
Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @picnixz for commit b175558 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F145201%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 25, 2026
@raminfp
Copy link
Copy Markdown
Contributor Author

raminfp commented Mar 19, 2026

CC: @picnixz

@picnixz
Copy link
Copy Markdown
Member

picnixz commented Mar 22, 2026

Tests are failing.

@raminfp raminfp requested a review from picnixz March 23, 2026 04:00
@gpshead gpshead self-assigned this Apr 11, 2026
@gpshead gpshead added the needs backport to 3.14 bugs and security fixes label Apr 11, 2026
@gpshead gpshead merged commit c29d756 into python:main Apr 11, 2026
49 checks passed
@miss-islington-app
Copy link
Copy Markdown

Thanks @raminfp for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link
Copy Markdown

Sorry, @raminfp and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c29d75610b40d2052dc7a5394b416305adf61281 3.14

@gpshead gpshead removed the needs backport to 3.14 bugs and security fixes label Apr 11, 2026
@picnixz
Copy link
Copy Markdown
Member

picnixz commented Apr 11, 2026

Yes, it's a 3.15-only change (it's when I used OpenSSL 3 HMAC EVP API)

@raminfp raminfp deleted the fix-gh-145200-hashlib-hmac-ctx-leak branch April 12, 2026 04:58
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
…pythonGH-145201)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants