Skip to content

Commit

Permalink
Add a test for CVE-2022-4450
Browse files Browse the repository at this point in the history
Call PEM_read_bio_ex() and expect a failure. There should be no dangling
ptrs and therefore there should be no double free if we free the ptrs on
error.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
  • Loading branch information
mattcaswell authored and t8m committed Feb 7, 2023
1 parent 7e1d844 commit de3ab47
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/pemtest.c
Expand Up @@ -96,12 +96,42 @@ static int test_cert_key_cert(void)
return 1;
}

static int test_empty_payload(void)
{
BIO *b;
static char *emptypay =
"-----BEGIN CERTIFICATE-----\n"
"-\n" /* Base64 EOF character */
"-----END CERTIFICATE-----";
char *name = NULL, *header = NULL;
unsigned char *data = NULL;
long len;
int ret = 0;

b = BIO_new_mem_buf(emptypay, strlen(emptypay));
if (!TEST_ptr(b))
return 0;

/* Expected to fail because the payload is empty */
if (!TEST_false(PEM_read_bio_ex(b, &name, &header, &data, &len, 0)))
goto err;

ret = 1;
err:
OPENSSL_free(name);
OPENSSL_free(header);
OPENSSL_free(data);
BIO_free(b);
return ret;
}

int setup_tests(void)
{
if (!TEST_ptr(pemfile = test_get_argument(0)))
return 0;
ADD_ALL_TESTS(test_b64, OSSL_NELEM(b64_pem_data));
ADD_TEST(test_invalid);
ADD_TEST(test_cert_key_cert);
ADD_TEST(test_empty_payload);
return 1;
}

0 comments on commit de3ab47

Please sign in to comment.