Skip to content

Commit

Permalink
test/crltest.c: Add check for glue2bio
Browse files Browse the repository at this point in the history
As the glue2bio() could return NULL pointer if fails,
it should be better to check the return value in order
to avoid the use of NULL pointer.

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from #17718)
  • Loading branch information
JiangJias authored and paulidale committed Feb 24, 2022
1 parent cf21d1c commit 18cb174
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions test/crltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,16 @@ static BIO *glue2bio(const char **pem, char **out)
*/
static X509_CRL *CRL_from_strings(const char **pem)
{
X509_CRL *crl;
char *p;
BIO *b = glue2bio(pem, &p);
X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);

if (b == NULL) {
OPENSSL_free(p);
return NULL;
}

crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);

OPENSSL_free(p);
BIO_free(b);
Expand All @@ -214,9 +221,16 @@ static X509_CRL *CRL_from_strings(const char **pem)
*/
static X509 *X509_from_strings(const char **pem)
{
X509 *x;
char *p;
BIO *b = glue2bio(pem, &p);
X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL);

if (b == NULL) {
OPENSSL_free(p);
return NULL;
}

x = PEM_read_bio_X509(b, NULL, NULL, NULL);

OPENSSL_free(p);
BIO_free(b);
Expand Down Expand Up @@ -363,6 +377,12 @@ static int test_reuse_crl(void)
char *p;
BIO *b = glue2bio(kRevokedCRL, &p);

if (b == NULL) {
OPENSSL_free(p);
X509_CRL_free(reused_crl);
return 0;
}

reused_crl = PEM_read_bio_X509_CRL(b, &reused_crl, NULL, NULL);

OPENSSL_free(p);
Expand Down

0 comments on commit 18cb174

Please sign in to comment.