From: Dr. Stephen Henson Date: Sat, 17 Sep 2016 11:36:58 +0000 (+0100) Subject: Fix small OOB reads. X-Git-Tag: OpenSSL_1_0_2i~13 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ff553f837172ecb2b5c8eca257ec3c5619a4b299;p=oweals%2Fopenssl.git Fix small OOB reads. In ssl3_get_client_certificate, ssl3_get_server_certificate and ssl3_get_certificate_request check we have enough room before reading a length. Thanks to Shi Lei (Gear Team, Qihoo 360 Inc.) for reporting these bugs. CVE-2016-6306 Reviewed-by: Richard Levitte Reviewed-by: Matt Caswell --- diff --git a/ssl/s3_clnt.c b/ssl/s3_clnt.c index 36833f7304..d2afaa5b9f 100644 --- a/ssl/s3_clnt.c +++ b/ssl/s3_clnt.c @@ -1216,6 +1216,12 @@ int ssl3_get_server_certificate(SSL *s) goto f_err; } for (nc = 0; nc < llen;) { + if (nc + 3 > llen) { + al = SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE, + SSL_R_CERT_LENGTH_MISMATCH); + goto f_err; + } n2l3(p, l); if ((l + nc + 3) > llen) { al = SSL_AD_DECODE_ERROR; @@ -2171,6 +2177,11 @@ int ssl3_get_certificate_request(SSL *s) } for (nc = 0; nc < llen;) { + if (nc + 2 > llen) { + ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); + SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST, SSL_R_CA_DN_TOO_LONG); + goto err; + } n2s(p, l); if ((l + nc + 2) > llen) { if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG)) diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c index 7c19753853..01ccd5d2ae 100644 --- a/ssl/s3_srvr.c +++ b/ssl/s3_srvr.c @@ -3220,6 +3220,12 @@ int ssl3_get_client_certificate(SSL *s) goto f_err; } for (nc = 0; nc < llen;) { + if (nc + 3 > llen) { + al = SSL_AD_DECODE_ERROR; + SSLerr(SSL_F_SSL3_GET_CLIENT_CERTIFICATE, + SSL_R_CERT_LENGTH_MISMATCH); + goto f_err; + } n2l3(p, l); if ((l + nc + 3) > llen) { al = SSL_AD_DECODE_ERROR;