Avoid segfault if ret==0.
[openssl.git] / crypto / bn / bn_gcd.c
index 7649f63fd22ab2562d7cfe384fc39b5e379eeb2b..0248753f6dc9a0f1499fb19d092d0c7d5b37b640 100644 (file)
@@ -140,6 +140,7 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
        ret=1;
 err:
        BN_CTX_end(ctx);
+       bn_check_top(r);
        return(ret);
        }
 
@@ -194,6 +195,7 @@ static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
                {
                if (!BN_lshift(a,a,shifts)) goto err;
                }
+       bn_check_top(a);
        return(a);
 err:
        return(NULL);
@@ -486,5 +488,7 @@ BIGNUM *BN_mod_inverse(BIGNUM *in,
 err:
        if ((ret == NULL) && (in == NULL)) BN_free(R);
        BN_CTX_end(ctx);
+       if (ret)
+               bn_check_top(ret);
        return(ret);
        }