Null-check SSL_HANDSHAKE first in SSL_serialize_handshake_hints After boringssl-review.googlesource.com/c/boringssl/+/97127, if SSL_serialize_handshake_hints is erroneously called for a client, the SSL_HANDSHAKE gets dereferenced which may cause a crash due to a NULL deref. This is an error anyway, but the aforementioned CL did not intend to change any behavior, so return an error first rather than potentially crashing if called for a client, and also NULL-check the SSL_HANDSHAKE. Change-Id: I4cc241757667ae2cc18e45827182e14d6a6a6964 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/98187 Reviewed-by: David Benjamin <davidben@google.com> Presubmit-BoringSSL-Verified: boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Lily Chen <chlily@google.com>
diff --git a/ssl/handoff.cc b/ssl/handoff.cc index 7f346c3..67ce1e5 100644 --- a/ssl/handoff.cc +++ b/ssl/handoff.cc
@@ -937,12 +937,12 @@ int SSL_serialize_handshake_hints(const SSL *ssl, CBB *out) { const SSL_HANDSHAKE *hs = ssl->s3->hs.get(); - const SSL_HANDSHAKE_HINTS *const hints = hs->pending_hints.get(); - if (!ssl->server || hints == nullptr) { + if (!ssl->server || hs == nullptr || hs->pending_hints == nullptr) { OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } + const SSL_HANDSHAKE_HINTS *const hints = hs->pending_hints.get(); CBB seq, child; if (!CBB_add_asn1(out, &seq, CBS_ASN1_SEQUENCE)) { return 0;