From: Benjamin Kaduk Date: Fri, 19 Feb 2021 21:46:49 +0000 (-0800) Subject: test_ecpub: verify returned length after encoding X-Git-Tag: openssl-3.0.0-alpha13~149 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad7cb0bf5cb9b014d34327cb35ecdd609a3d4dd4;p=thirdparty%2Fopenssl.git test_ecpub: verify returned length after encoding 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 Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/14291) --- diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c index 487767f651d..844c8da3117 100644 --- a/test/evp_extra_test.c +++ b/test/evp_extra_test.c @@ -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;