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

Skip to content

Commit d92816d

Browse files
miss-islingtonZackerySpytz
authored andcommitted
bpo-34824: Fix a possible NULL pointer dereference in _ssl.c (GH-9606) (GH-9744)
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 5e808f9 commit d92816d

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

43674367
nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len);
4368-
/* There should never be any short reads but check anyway. */
4369-
if ((nbytes < len) && (_PyBytes_Resize(&result, len) < 0)) {
4368+
if (nbytes < 0) {
43704369
Py_DECREF(result);
4370+
_setSSLError(NULL, 0, __FILE__, __LINE__);
43714371
return NULL;
43724372
}
43734373

4374+
/* There should never be any short reads but check anyway. */
4375+
if (nbytes < len) {
4376+
_PyBytes_Resize(&result, nbytes);
4377+
}
4378+
43744379
return result;
43754380
}
43764381

0 commit comments

Comments
 (0)