bpo-34824: Fix a possible NULL pointer dereference in _ssl.c (GH-9606)
authorZackery Spytz <zspytz@gmail.com>
Sat, 6 Oct 2018 17:41:45 +0000 (11:41 -0600)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 6 Oct 2018 17:41:45 +0000 (10:41 -0700)
On failure, _PyBytes_Resize() will deallocate the bytes object and set
"result" to NULL.

https://bugs.python.org/issue34824

Misc/NEWS.d/next/Core and Builtins/2018-09-27-11-10-02.bpo-34824.VLlCaU.rst [new file with mode: 0644]
Modules/_ssl.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-09-27-11-10-02.bpo-34824.VLlCaU.rst b/Misc/NEWS.d/next/Core and Builtins/2018-09-27-11-10-02.bpo-34824.VLlCaU.rst
new file mode 100644 (file)
index 0000000..fe95b89
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a possible null pointer dereference in Modules/_ssl.c. Patch by Zackery
+Spytz.
index 96bdac44917e727a83a5a92a809b887f4793c10c..93498f475609d069205c56b1ee3b341a97dc5d25 100644 (file)
@@ -4710,12 +4710,17 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
         return result;
 
     nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len);
-    /* There should never be any short reads but check anyway. */
-    if ((nbytes < len) && (_PyBytes_Resize(&result, len) < 0)) {
+    if (nbytes < 0) {
         Py_DECREF(result);
+        _setSSLError(NULL, 0, __FILE__, __LINE__);
         return NULL;
     }
 
+    /* There should never be any short reads but check anyway. */
+    if (nbytes < len) {
+        _PyBytes_Resize(&result, nbytes);
+    }
+
     return result;
 }