Skip to content

Commit

Permalink
provider: return error if buf too small when get ec pubkey param
Browse files Browse the repository at this point in the history
FIX: #20889
Should check buffer size when get ec pubkey param,
if buffer is not NULL and size too-small, return 0 as error code.

Signed-off-by: Yi Li <yi1.li@intel.com>
  • Loading branch information
liyi77 committed May 9, 2023
1 parent 42a6a25 commit 01a84ab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion providers/implementations/keymgmt/ec_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ int common_get_params(void *key, OSSL_PARAM params[], int sm2)
}
p->return_size = EC_POINT_point2oct(ecg, ecp,
POINT_CONVERSION_UNCOMPRESSED,
p->data, p->return_size, bnctx);
p->data, p->data_size, bnctx);
if (p->return_size == 0)
goto err;
}
Expand Down
22 changes: 22 additions & 0 deletions test/evp_extra_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,8 @@ static int test_EC_priv_pub(void)
BIGNUM *priv = NULL;
int ret = 0;
unsigned char *encoded = NULL;
size_t len = 0;
unsigned char buffer[128];

/*
* Setup the parameters for our pkey object. For our purposes they don't
Expand Down Expand Up @@ -1019,6 +1021,26 @@ static int test_EC_priv_pub(void)
goto err;
}

/* Positive and negative testcase for EVP_PKEY_get_octet_string_param */
if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
buffer, sizeof(buffer), &len), 1)
|| !TEST_int_eq(len, 65))
goto err;

len = 0;
if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
NULL, 0, &len), 1)
|| !TEST_int_eq(len, 65))
goto err;

/* too-short buffer len*/
if (!TEST_int_eq(EVP_PKEY_get_octet_string_param(params_and_pub,
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY,
buffer, 10, &len), 0))
goto err;

ret = 1;
err:
OSSL_PARAM_free(params);
Expand Down

0 comments on commit 01a84ab

Please sign in to comment.