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 18:00:02 +0000 (19:00 +0100)
(cherry picked from commit 7d89b3bf42e4b4067371ab33ef7631434e41d1e4)

ssl/t1_lib.c

index 4710a885a7c10af3296121a2866086cdbfe4c1f0..3b8d5153eb6f669e96b3aaf3b7c156bb0dff40d7 100644 (file)
@@ -617,6 +617,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:
@@ -844,6 +846,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: