Fix reading heap overflow in a test case
authorPaul Yang <yang.yang@baishancloud.com>
Mon, 9 Oct 2017 09:16:17 +0000 (17:16 +0800)
committerMatt Caswell <matt@openssl.org>
Mon, 16 Oct 2017 09:08:53 +0000 (10:08 +0100)
Caught by AddressSanitizer

Reviewed-by: Ben Kaduk <kaduk@mit.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4497)

test/sslapitest.c

index c1137b08a54fc8c97f631b61927d86cad72ab466..3412aff17f1a519f25b9820e248c9722e7076cee 100644 (file)
@@ -1974,15 +1974,16 @@ static int hostname_cb(SSL *s, int *al, void *arg)
 
 static const char *servalpn;
 
-static int alpn_select_cb (SSL *ssl, const unsigned char **out, unsigned char *outlen,
-                    const unsigned char *in, unsigned int inlen, void *arg)
+static int alpn_select_cb(SSL *ssl, const unsigned char **out,
+                          unsigned char *outlen, const unsigned char *in,
+                          unsigned int inlen, void *arg)
 {
-    unsigned int i, protlen = 0;
+    unsigned int protlen = 0;
     const unsigned char *prot;
 
-    for (i = 0, prot = in; i < inlen; i += protlen, prot += protlen) {
-        protlen = *(prot++);
-        if (inlen - i < protlen)
+    for (prot = in; prot < in + inlen; prot += protlen) {
+        protlen = *prot++;
+        if (in + inlen - prot < protlen)
             return SSL_TLSEXT_ERR_NOACK;
 
         if (protlen == strlen(servalpn)