From 81f433540ef5f34769e0febd429be065dff886fa Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Fri, 26 Aug 2016 09:22:56 -0700 Subject: [PATCH] Don't crash when a session callback returns NULL. 4aa154e08fdc0a0c57df9e19ea3a303a2b99aed0 changed the code to assume that a session callback will zero the |copy| out-arg before returning NULL. In practice this doesn't always happen and we should be robust against it. Change-Id: I0fd14969df836e0fa4f68ded8648fea8094ff9d7 Reviewed-on: https://boringssl-review.googlesource.com/10640 Reviewed-by: David Benjamin Commit-Queue: Adam Langley CQ-Verified: CQ bot account: commit-bot@chromium.org --- ssl/ssl_session.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ssl/ssl_session.c b/ssl/ssl_session.c index e763fd35..3a56dcd3 100644 --- a/ssl/ssl_session.c +++ b/ssl/ssl_session.c @@ -633,6 +633,10 @@ static enum ssl_session_result_t ssl_lookup_session( session = ssl->initial_ctx->get_session_cb(ssl, (uint8_t *)session_id, session_id_len, ©); + if (session == NULL) { + return ssl_session_success; + } + if (session == SSL_magic_pending_session_ptr()) { return ssl_session_retry; } @@ -646,8 +650,7 @@ static enum ssl_session_result_t ssl_lookup_session( } /* Add the externally cached session to the internal cache if necessary. */ - if (session != NULL && - !(ssl->initial_ctx->session_cache_mode & + if (!(ssl->initial_ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE)) { SSL_CTX_add_session(ssl->initial_ctx, session); }