Skip to content

Commit

Permalink
bpo-41056: Fix a NULL pointer dereference on MemoryError within the s…
Browse files Browse the repository at this point in the history
…sl module. (GH-21009)

Detected by Coverity.
  • Loading branch information
gpshead committed Jun 20, 2020
1 parent 314858e commit eb0d5c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
@@ -0,0 +1 @@
Fix a NULL pointer dereference within the ssl module during a MemoryError in the keylog callback. (discovered by Coverity)
12 changes: 6 additions & 6 deletions Modules/_ssl/debughelpers.c
Expand Up @@ -125,6 +125,12 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)

threadstate = PyGILState_Ensure();

ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl);
assert(PySSLSocket_Check(ssl_obj));
if (ssl_obj->ctx->keylog_bio == NULL) {
return;
}

/* Allocate a static lock to synchronize writes to keylog file.
* The lock is neither released on exit nor on fork(). The lock is
* also shared between all SSLContexts although contexts may write to
Expand All @@ -141,12 +147,6 @@ _PySSL_keylog_callback(const SSL *ssl, const char *line)
}
}

ssl_obj = (PySSLSocket *)SSL_get_app_data(ssl);
assert(PySSLSocket_Check(ssl_obj));
if (ssl_obj->ctx->keylog_bio == NULL) {
return;
}

PySSL_BEGIN_ALLOW_THREADS
PyThread_acquire_lock(lock, 1);
res = BIO_printf(ssl_obj->ctx->keylog_bio, "%s\n", line);
Expand Down

0 comments on commit eb0d5c3

Please sign in to comment.