[3.13] gh-144833: Fix use-after-free in SSL module when SSL_new() fails (GH-144843) by miss-islington · Pull Request #144859 · python/cpython (original) (raw)

@raminfp @miss-islington

pythonGH-144843)

In newPySSLSocket(), when SSL_new() returns NULL, Py_DECREF(self) was called before _setSSLError(get_state_ctx(self), ...), causing a use-after-free. Additionally, get_state_ctx() was called with self (PySSLSocket*) instead of sslctx (PySSLContext*), which is a type confusion bug.

Fix by calling _setSSLError() before Py_DECREF() and using sslctx instead of self for get_state_ctx(). (cherry picked from commit c91638c)

Co-authored-by: Ramin Farajpour Cami ramin.blackhat@gmail.com

@bedevere-app bot mentioned this pull request

Feb 16, 2026

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

[ Show hidden characters]({{ revealButtonHref }})