Commit cee0cdbc authored by Bernd Edlinger's avatar Bernd Edlinger Committed by Richard Levitte
Browse files

Fix a ssl session leak due to OOM in lh_SSL_SESSION_insert



- s == NULL can mean c is a new session *or* lh_insert was
  unable to create a hash entry.
- use lh_SSL_SESSION_retrieve to check for this error condition.
- If it happens simply remove the extra reference again.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2138)
(cherry picked from commit 38088ce9)
parent b81aadde
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -660,6 +660,15 @@ int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
         * obtain the same session from an external cache)
         */
        s = NULL;
    } else if (s == NULL &&
               lh_SSL_SESSION_retrieve(ctx->sessions, c) == NULL) {
        /* s == NULL can also mean OOM error in lh_SSL_SESSION_insert ... */

        /*
         * ... so take back the extra reference and also don't add
         * the session to the SSL_SESSION_list at this time
         */
        s = c;
    }

    /* Put at the head of the queue unless it is already in the cache */