Fix incorrect return check of BN_bn2nativepad
authorPW Hu <jlu.hpw@foxmail.com>
Mon, 1 Nov 2021 07:08:51 +0000 (15:08 +0800)
committerPW Hu <jlu.hpw@foxmail.com>
Mon, 1 Nov 2021 07:08:51 +0000 (15:08 +0800)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16943)

crypto/evp/ctrl_params_translate.c
test/keymgmt_internal_test.c

index b17ce3cbf9b9370891434abb17abad6a1d3ba445..d17017a78e8185d96bb3f71b302b5ee5304a9f1e 100644 (file)
@@ -465,8 +465,8 @@ static int default_fixup_args(enum state state,
                         ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE);
                         return 0;
                     }
-                    if (!BN_bn2nativepad(ctx->p2,
-                                         ctx->allocated_buf, ctx->buflen)) {
+                    if (BN_bn2nativepad(ctx->p2,
+                                         ctx->allocated_buf, ctx->buflen) < 0) {
                         OPENSSL_free(ctx->allocated_buf);
                         ctx->allocated_buf = NULL;
                         return 0;
index 40fc464bc22c1f2e039f3961837aa0aa0c56f187..dd0de2f599277b21aa07d58b432941e51c8064d4 100644 (file)
@@ -88,7 +88,7 @@ static int get_ulong_via_BN(const OSSL_PARAM *p, unsigned long *goal)
     int ret = 1;                 /* Ever so hopeful */
 
     if (!TEST_true(OSSL_PARAM_get_BN(p, &n))
-        || !TEST_true(BN_bn2nativepad(n, (unsigned char *)goal, sizeof(*goal))))
+        || !TEST_int_ge(BN_bn2nativepad(n, (unsigned char *)goal, sizeof(*goal)), 0))
         ret = 0;
     BN_free(n);
     return ret;