Skip to content

Commit

Permalink
[3.12] gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (
Browse files Browse the repository at this point in the history
GH-106832) (#106835)

gh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (GH-106832)
(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <[email protected]>
  • Loading branch information
miss-islington and sobolevn authored Jul 17, 2023
1 parent 497bfd5 commit 2eef81e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix potential missing ``NULL`` check of ``d2i_SSL_SESSION`` result in
``_ssl.c``.
7 changes: 4 additions & 3 deletions Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,7 @@ _ssl_session_dup(SSL_SESSION *session) {
/* get length */
slen = i2d_SSL_SESSION(session, NULL);
if (slen == 0 || slen > 0xFF00) {
PyErr_SetString(PyExc_ValueError, "i2d() failed.");
PyErr_SetString(PyExc_ValueError, "i2d() failed");
goto error;
}
if ((senc = PyMem_Malloc(slen)) == NULL) {
Expand All @@ -2788,12 +2788,13 @@ _ssl_session_dup(SSL_SESSION *session) {
}
p = senc;
if (!i2d_SSL_SESSION(session, &p)) {
PyErr_SetString(PyExc_ValueError, "i2d() failed.");
PyErr_SetString(PyExc_ValueError, "i2d() failed");
goto error;
}
const_p = senc;
newsession = d2i_SSL_SESSION(NULL, &const_p, slen);
if (session == NULL) {
if (newsession == NULL) {
PyErr_SetString(PyExc_ValueError, "d2i() failed");
goto error;
}
PyMem_Free(senc);
Expand Down

0 comments on commit 2eef81e

Please sign in to comment.