Skip to content

Commit

Permalink
pythongh-106831: Fix NULL check of d2i_SSL_SESSION() result in _ssl.c (
Browse files Browse the repository at this point in the history
…pythonGH-106832)

(cherry picked from commit ebf2c56)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
  • Loading branch information
sobolevn authored and miss-islington committed Jul 17, 2023
1 parent 263d8aa commit 8628b2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
@@ -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
Expand Up @@ -2800,7 +2800,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 @@ -2809,12 +2809,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 8628b2d

Please sign in to comment.