Skip to content

Commit f68283c

Browse files
committed
test/evp_test.c: Check too big output buffer sizes in PKEYKDF tests
EVP_PKEY_derive() should be able to cope with a too big buffer for fixed size outputs. However, we don't test that. This change modifies the PKEYKDF tests to ask EVP_PKEY_derive() what the desired output buffer size is, and as long as the returned value isn't absurd (indicating that anything goes), the output buffer is made to be twice as big as what is expected. Tests openssl#18517 Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#18533) (cherry picked from commit a0587aa)
1 parent 46c1c2d commit f68283c

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

test/evp_test.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -2897,7 +2897,23 @@ static int pkey_kdf_test_run(EVP_TEST *t)
28972897
{
28982898
PKEY_KDF_DATA *expected = t->data;
28992899
unsigned char *got = NULL;
2900-
size_t got_len = expected->output_len;
2900+
size_t got_len = 0;
2901+
2902+
/* Find out the KDF output size */
2903+
if (EVP_PKEY_derive(expected->ctx, NULL, &got_len) <= 0) {
2904+
t->err = "INTERNAL_ERROR";
2905+
goto err;
2906+
}
2907+
2908+
/*
2909+
* We may get an absurd output size, which signals that anything goes.
2910+
* If not, we specify a too big buffer for the output, to test that
2911+
* EVP_PKEY_derive() can cope with it.
2912+
*/
2913+
if (got_len == SIZE_MAX || got_len == 0)
2914+
got_len = expected->output_len;
2915+
else
2916+
got_len = expected->output_len * 2;
29012917

29022918
if (!TEST_ptr(got = OPENSSL_malloc(got_len == 0 ? 1 : got_len))) {
29032919
t->err = "INTERNAL_ERROR";

0 commit comments

Comments
 (0)