Skip to content

Comments

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

Merged
Yhg1s merged 1 commit intopython:3.12from
miss-islington:backport-c91638c-3.12
Feb 23, 2026
Merged

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

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>
@Yhg1s Yhg1s merged commit 9fc477c into python:3.12 Feb 23, 2026
32 checks passed
@miss-islington miss-islington deleted the backport-c91638c-3.12 branch February 23, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

5 participants