]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test_ecpub: verify returned length after encoding
authorBenjamin Kaduk <bkaduk@akamai.com>
Fri, 19 Feb 2021 21:46:49 +0000 (13:46 -0800)
committerRichard Levitte <levitte@openssl.org>
Sat, 27 Feb 2021 15:14:09 +0000 (16:14 +0100)
Save the length we got from querying how much space was needed, and
check that the actual encoding call returned the same length.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14291)

test/evp_extra_test.c

index 487767f651d6270504318ade435370da21b255c4..844c8da3117ef5dd0c5dd42b45af0e08a23914ce 100644 (file)
@@ -2423,7 +2423,7 @@ static int ecpub_nids[] = { NID_brainpoolP256r1, NID_X9_62_prime256v1,
 
 static int test_ecpub(int idx)
 {
-    int ret = 0, len;
+    int ret = 0, len, savelen;
     int nid;
     unsigned char buf[1024];
     unsigned char *p;
@@ -2439,12 +2439,14 @@ static int test_ecpub(int idx)
         || !TEST_true(EVP_PKEY_keygen(ctx, &pkey)))
         goto done;
     len = i2d_PublicKey(pkey, NULL);
+    savelen = len;
     if (!TEST_int_ge(len, 1)
         || !TEST_int_lt(len, 1024))
         goto done;
     p = buf;
     len = i2d_PublicKey(pkey, &p);
-    if (!TEST_int_ge(len, 1))
+    if (!TEST_int_ge(len, 1)
+            || !TEST_int_eq(len, savelen))
         goto done;
 
     ret = 1;