Check there is enough room for extension.
authorDavid Benjamin <davidben@google.com>
Mon, 2 Jun 2014 17:55:20 +0000 (18:55 +0100)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 2 Jun 2014 17:59:48 +0000 (18:59 +0100)
(cherry picked from commit 7d89b3bf42e4b4067371ab33ef7631434e41d1e4)

ssl/t1_lib.c

index 07674405d86e016aae8b27d68c84a5aeb9859a3b..eefe93ed13281aaf9505aa6e7726ddc73a6f9a5d 100644 (file)
@@ -1380,6 +1380,8 @@ unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned cha
 
 #ifndef OPENSSL_NO_HEARTBEATS
        /* Add Heartbeat extension */
+       if ((limit - ret - 4 - 1) < 0)
+               return NULL;
        s2n(TLSEXT_TYPE_heartbeat,ret);
        s2n(1,ret);
        /* Set mode:
@@ -1658,6 +1660,8 @@ unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned cha
        /* Add Heartbeat extension if we've received one */
        if (s->tlsext_heartbeat & SSL_TLSEXT_HB_ENABLED)
                {
+               if ((limit - ret - 4 - 1) < 0)
+                       return NULL;
                s2n(TLSEXT_TYPE_heartbeat,ret);
                s2n(1,ret);
                /* Set mode: