Add sanity check to PRF
authorMatt Caswell <matt@openssl.org>
Thu, 12 Mar 2015 14:37:26 +0000 (14:37 +0000)
committerMatt Caswell <matt@openssl.org>
Tue, 17 Mar 2015 13:39:53 +0000 (13:39 +0000)
The function tls1_PRF counts the number of digests in use and partitions
security evenly between them. There always needs to be at least one digest
in use, otherwise this is an internal error. Add a sanity check for this.

Reviewed-by: Richard Levitte <levitte@openssl.org>
ssl/t1_enc.c

index 1833eb7646128a1ea0269b2a6aa0de923cdf1c60..26f8415dcbb8fb34b3f94d8b5cdd41bbaa560303 100644 (file)
@@ -260,6 +260,11 @@ static int tls1_PRF(long digest_mask,
         if ((m << TLS1_PRF_DGST_SHIFT) & digest_mask)
             count++;
     }
         if ((m << TLS1_PRF_DGST_SHIFT) & digest_mask)
             count++;
     }
+    if(!count) {
+        /* Should never happen */
+        SSLerr(SSL_F_TLS1_PRF, ERR_R_INTERNAL_ERROR);
+        goto err;
+    }
     len = slen / count;
     if (count == 1)
         slen = 0;
     len = slen / count;
     if (count == 1)
         slen = 0;