Skip to content

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

Merged
gpshead merged 1 commit intopython:3.14from
miss-islington:backport-c91638c-3.14
Feb 16, 2026
Merged

[3.14] gh-144833: Fix use-after-free in SSL module when SSL_new() fails (GH-144843)#144858
gpshead merged 1 commit intopython:3.14from
miss-islington:backport-c91638c-3.14

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Feb 16, 2026

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

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>
@gpshead gpshead enabled auto-merge (squash) February 16, 2026 02:44
@gpshead gpshead merged commit 53b8e64 into python:3.14 Feb 16, 2026
53 checks passed
@miss-islington miss-islington deleted the backport-c91638c-3.14 branch February 16, 2026 03:10
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.

3 participants