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
  • Loading branch information
sobolevn committed Jul 17, 2023
1 parent 8e9a1a0 commit ebf2c56
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 @@ -2808,7 +2808,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 @@ -2817,12 +2817,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 ebf2c56

Please sign in to comment.