Validate ClientHello session_id field length and send alert on failure
authorAlessandro Ghedini <alessandro@ghedini.me>
Wed, 13 Jan 2016 12:49:24 +0000 (12:49 +0000)
committerMatt Caswell <matt@openssl.org>
Tue, 19 Jan 2016 15:37:16 +0000 (15:37 +0000)
RT#4080

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
ssl/s2_srvr.c
ssl/s3_srvr.c
ssl/ssl_sess.c

index 4289272b73d3dc29691de99d29a37ecf8090fefd..5e2e0acc357cfd92c8e998d86aa80262c4fd4eef 100644 (file)
@@ -598,6 +598,11 @@ static int get_client_hello(SSL *s)
         s->s2->tmp.cipher_spec_length = i;
         n2s(p, i);
         s->s2->tmp.session_id_length = i;
+        if ((i < 0) || (i > SSL_MAX_SSL_SESSION_ID_LENGTH)) {
+            ssl2_return_error(s, SSL2_PE_UNDEFINED_ERROR);
+            SSLerr(SSL_F_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);
+            return -1;
+        }
         n2s(p, i);
         s->s2->challenge_length = i;
         if ((i < SSL2_MIN_CHALLENGE_LENGTH) ||
index 9d6886c07da78913ee6a835e8ce26017de1b9afd..9b05f189d52a66005d7de0d7f3c54450d63e0213 100644 (file)
@@ -1004,6 +1004,12 @@ int ssl3_get_client_hello(SSL *s)
         goto f_err;
     }
 
+    if ((j < 0) || (j > SSL_MAX_SSL_SESSION_ID_LENGTH)) {
+        al = SSL_AD_DECODE_ERROR;
+        SSLerr(SSL_F_SSL3_GET_CLIENT_HELLO, SSL_R_LENGTH_MISMATCH);
+        goto f_err;
+    }
+
     s->hit = 0;
     /*
      * Versions before 0.9.7 always allow clients to resume sessions in
index 68390d3108099340f9a69dbebf07c1d7464974f6..b182998343844a8626262453e8b5f6f62dbb179c 100644 (file)
@@ -573,9 +573,6 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len,
     int r;
 #endif
 
-    if (len < 0 || len > SSL_MAX_SSL_SESSION_ID_LENGTH)
-        goto err;
-
     if (session_id + len > limit) {
         fatal = 1;
         goto err;