Skip to content

Commit 4ec9f64

Browse files
miss-islingtonZackerySpytz
authored andcommitted
bpo-34824: Fix a possible NULL pointer dereference in _ssl.c (GH-9606) (GH-9743)
On failure, _PyBytes_Resize() will deallocate the bytes object and set "result" to NULL. https://bugs.python.org/issue34824 (cherry picked from commit 365ad2e) Co-authored-by: Zackery Spytz <[email protected]>
1 parent c119d59 commit 4ec9f64

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible null pointer dereference in Modules/_ssl.c. Patch by Zackery
2+
Spytz.

Modules/_ssl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,12 +4711,17 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
47114711
return result;
47124712

47134713
nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len);
4714-
/* There should never be any short reads but check anyway. */
4715-
if ((nbytes < len) && (_PyBytes_Resize(&result, len) < 0)) {
4714+
if (nbytes < 0) {
47164715
Py_DECREF(result);
4716+
_setSSLError(NULL, 0, __FILE__, __LINE__);
47174717
return NULL;
47184718
}
47194719

4720+
/* There should never be any short reads but check anyway. */
4721+
if (nbytes < len) {
4722+
_PyBytes_Resize(&result, nbytes);
4723+
}
4724+
47204725
return result;
47214726
}
47224727

0 commit comments

Comments
 (0)