SIGN IN SIGN UP
python / cpython UNCLAIMED

The Python programming language

0 0 1 Python

[3.12] gh-144833: Fix use-after-free in SSL module when SSL_new() fails (GH-144843) (#144860)

gh-144833: Fix use-after-free in SSL module when SSL_new() fails (GH-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 c91638ca0671b8038831f963ed44e66cdda006a2)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
M
Miss Islington (bot) committed
9fc477cd1da0813709d021dc960be1aa3aa1e670
Parent: e417f05
Committed by GitHub <noreply@github.com> on 2/23/2026, 2:50:38 PM