]> granicus.if.org Git - openssl/commitdiff
Fix a mem leak in NPN handling
authorMatt Caswell <matt@openssl.org>
Fri, 9 Sep 2016 09:53:39 +0000 (10:53 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 22 Sep 2016 08:22:05 +0000 (09:22 +0100)
If a server sent multiple NPN extensions in a single ClientHello then a
mem leak can occur. This will only happen where the client has requested
NPN in the first place. It does not occur during renegotiation. Therefore
the maximum that could be leaked in a single connection with a malicious
server is 64k (the maximum size of the ServerHello extensions section). As
this is client side, only occurs if NPN has been requested and does not
occur during renegotiation this is unlikely to be exploitable.

Issue reported by Shi Lei.

Reviewed-by: Rich Salz <rsalz@openssl.org>
ssl/t1_lib.c

index e4b4e27dd7fc3560df7a4ea2c6b13ec3d563aa1f..7831046b9261396451d6bad61c8941f865a2e944 100644 (file)
@@ -2722,6 +2722,11 @@ static int ssl_scan_serverhello_tlsext(SSL *s, unsigned char **p,
                 *al = TLS1_AD_INTERNAL_ERROR;
                 return 0;
             }
+            /*
+             * Could be non-NULL if server has sent multiple NPN extensions in
+             * a single Serverhello
+             */
+            OPENSSL_free(s->next_proto_negotiated);
             s->next_proto_negotiated = OPENSSL_malloc(selected_len);
             if (!s->next_proto_negotiated) {
                 *al = TLS1_AD_INTERNAL_ERROR;