Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 365ad2e

Browse files
ZackerySpytzmiss-islington
authored andcommitted
bpo-34824: Fix a possible NULL pointer dereference in _ssl.c (GH-9606)
On failure, _PyBytes_Resize() will deallocate the bytes object and set "result" to NULL. https://bugs.python.org/issue34824
1 parent 683281f commit 365ad2e

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

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
@@ -4710,12 +4710,17 @@ _ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len)
47104710
return result;
47114711

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

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

0 commit comments

Comments
 (0)