diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-06-21 19:11:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 19:11:41 (GMT) |
commit | fbf94af2af3c09493481b8559b84f6e9f0628c37 (patch) | |
tree | f417de4c6bd9efda321864e5c578e6c522fd91e5 | |
parent | 814b07bf814a804f60b897d18f1dbb5578b2c7fd (diff) | |
download | cpython-fbf94af2af3c09493481b8559b84f6e9f0628c37.zip cpython-fbf94af2af3c09493481b8559b84f6e9f0628c37.tar.gz cpython-fbf94af2af3c09493481b8559b84f6e9f0628c37.tar.bz2 |
bpo-41056: Fix a NULL pointer dereference on MemoryError within the ssl module. (GH-21009)
Detected by Coverity.
(cherry picked from commit eb0d5c38de7f970d8cd8524f4163d831c7720f51)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst | 1 | ||||
-rw-r--r-- | Modules/_ssl/debughelpers.c | 12 |
2 files changed, 7 insertions, 6 deletions
diff --git a/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst b/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst new file mode 100644 index 0000000..1776f0d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-06-20-18-35-43.bpo-41056.Garcle.rst @@ -0,0 +1 @@ +Fix a NULL pointer dereference within the ssl module during a MemoryError in the keylog callback. (discovered by Coverity)
\ No newline at end of file diff --git a/Modules/_ssl/debughelpers.c b/Modules/_ssl/debughelpers.c index 858b3d7..b840da2 100644 --- a/Modules/_ssl/debughelpers.c +++ b/Modules/_ssl/debughelpers.c @@ -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 @@ -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); |