Add missing return value checks
authorMatt Caswell <matt@openssl.org>
Fri, 29 Jan 2016 09:40:03 +0000 (09:40 +0000)
committerMatt Caswell <matt@openssl.org>
Fri, 29 Jan 2016 11:58:45 +0000 (11:58 +0000)
The function DH_check_pub_key() was missing some return value checks in
some calls to BN functions.

RT#4278

Reviewed-by: Andy Polyakov <appro@openssl.org>
(cherry picked from commit f5a12207eccfd814bde68b880a96910dfa25f164)

crypto/dh/dh_check.c

index 5adedc0d264e99aae5d68ef2e4c5585dcfd33de3..027704111432d24cf7f6923bd8a2d910c6a5b464 100644 (file)
@@ -160,13 +160,12 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
         goto err;
     BN_CTX_start(ctx);
     tmp = BN_CTX_get(ctx);
-    if (tmp == NULL)
+    if (tmp == NULL || !BN_set_word(tmp, 1))
         goto err;
-    BN_set_word(tmp, 1);
     if (BN_cmp(pub_key, tmp) <= 0)
         *ret |= DH_CHECK_PUBKEY_TOO_SMALL;
-    BN_copy(tmp, dh->p);
-    BN_sub_word(tmp, 1);
+    if (BN_copy(tmp, dh->p) == NULL || !BN_sub_word(tmp, 1))
+        goto err;
     if (BN_cmp(pub_key, tmp) >= 0)
         *ret |= DH_CHECK_PUBKEY_TOO_LARGE;