Skip to content

Commit fbf94af

Browse files
bpo-41056: Fix a NULL pointer dereference on MemoryError within the ssl module. (GH-21009)
Detected by Coverity. (cherry picked from commit eb0d5c3) Co-authored-by: Gregory P. Smith <[email protected]>
1 parent 814b07b commit fbf94af

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a NULL pointer dereference within the ssl module during a MemoryError in the keylog callback. (discovered by Coverity)

Modules/_ssl/debughelpers.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
125125

126126
threadstate = PyGILState_Ensure();
127127

128+
ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl);
129+
assert(PySSLSocket_Check(ssl_obj));
130+
if (ssl_obj->ctx->keylog_bio == NULL) {
131+
return;
132+
}
133+
128134
/* Allocate a static lock to synchronize writes to keylog file.
129135
* The lock is neither released on exit nor on fork(). The lock is
130136
* also shared between all SSLContexts although contexts may write to
@@ -141,12 +147,6 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
141147
}
142148
}
143149

144-
ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl);
145-
assert(PySSLSocket_Check(ssl_obj));
146-
if (ssl_obj->ctx->keylog_bio == NULL) {
147-
return;
148-
}
149-
150150
PySSL_BEGIN_ALLOW_THREADS
151151
PyThread_acquire_lock(lock, 1);
152152
res = BIO_printf(ssl_obj->ctx->keylog_bio, "%s\n", line);

0 commit comments

Comments
 (0)