Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be7467f

Browse files
icy17mattcaswell
authored andcommitted
Add return check to BIO_new, SSL_CTX_new and EVP_PKEY_new
Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Matt Caswell <[email protected]> (Merged from #27829)
1 parent 0fe6c21 commit be7467f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

fuzz/server.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
540540

541541
/* This only fuzzes the initial flow from the client so far. */
542542
ctx = SSL_CTX_new(SSLv23_method());
543-
543+
OPENSSL_assert(ctx != NULL);
544544
ret = SSL_CTX_set_min_proto_version(ctx, 0);
545545
OPENSSL_assert(ret == 1);
546546
ret = SSL_CTX_set_cipher_list(ctx, "ALL:eNULL:@SECLEVEL=0");
@@ -552,6 +552,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
552552
privkey = d2i_RSAPrivateKey(NULL, &bufp, sizeof(kRSAPrivateKeyDER));
553553
OPENSSL_assert(privkey != NULL);
554554
pkey = EVP_PKEY_new();
555+
OPENSSL_assert(pkey != NULL);
555556
EVP_PKEY_assign_RSA(pkey, privkey);
556557
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
557558
OPENSSL_assert(ret == 1);
@@ -569,18 +570,21 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
569570
# ifndef OPENSSL_NO_DEPRECATED_3_0
570571
/* ECDSA */
571572
bio_buf = BIO_new(BIO_s_mem());
573+
OPENSSL_assert(bio_buf != NULL);
572574
OPENSSL_assert((size_t)BIO_write(bio_buf, ECDSAPrivateKeyPEM, sizeof(ECDSAPrivateKeyPEM)) == sizeof(ECDSAPrivateKeyPEM));
573575
ecdsakey = PEM_read_bio_ECPrivateKey(bio_buf, NULL, NULL, NULL);
574576
ERR_print_errors_fp(stderr);
575577
OPENSSL_assert(ecdsakey != NULL);
576578
BIO_free(bio_buf);
577579
pkey = EVP_PKEY_new();
580+
OPENSSL_assert(pkey != NULL);
578581
EVP_PKEY_assign_EC_KEY(pkey, ecdsakey);
579582
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
580583
OPENSSL_assert(ret == 1);
581584
EVP_PKEY_free(pkey);
582585
# endif
583586
bio_buf = BIO_new(BIO_s_mem());
587+
OPENSSL_assert(bio_buf != NULL);
584588
OPENSSL_assert((size_t)BIO_write(bio_buf, ECDSACertPEM, sizeof(ECDSACertPEM)) == sizeof(ECDSACertPEM));
585589
cert = PEM_read_bio_X509(bio_buf, NULL, NULL, NULL);
586590
OPENSSL_assert(cert != NULL);
@@ -593,18 +597,21 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
593597
#if !defined(OPENSSL_NO_DSA) && !defined(OPENSSL_NO_DEPRECATED_3_0)
594598
/* DSA */
595599
bio_buf = BIO_new(BIO_s_mem());
600+
OPENSSL_assert(bio_buf != NULL);
596601
OPENSSL_assert((size_t)BIO_write(bio_buf, DSAPrivateKeyPEM, sizeof(DSAPrivateKeyPEM)) == sizeof(DSAPrivateKeyPEM));
597602
dsakey = PEM_read_bio_DSAPrivateKey(bio_buf, NULL, NULL, NULL);
598603
ERR_print_errors_fp(stderr);
599604
OPENSSL_assert(dsakey != NULL);
600605
BIO_free(bio_buf);
601606
pkey = EVP_PKEY_new();
607+
OPENSSL_assert(pkey != NULL);
602608
EVP_PKEY_assign_DSA(pkey, dsakey);
603609
ret = SSL_CTX_use_PrivateKey(ctx, pkey);
604610
OPENSSL_assert(ret == 1);
605611
EVP_PKEY_free(pkey);
606612

607613
bio_buf = BIO_new(BIO_s_mem());
614+
OPENSSL_assert(bio_buf != NULL);
608615
OPENSSL_assert((size_t)BIO_write(bio_buf, DSACertPEM, sizeof(DSACertPEM)) == sizeof(DSACertPEM));
609616
cert = PEM_read_bio_X509(bio_buf, NULL, NULL, NULL);
610617
OPENSSL_assert(cert != NULL);
@@ -616,7 +623,9 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len)
616623

617624
server = SSL_new(ctx);
618625
in = BIO_new(BIO_s_mem());
626+
OPENSSL_assert(in != NULL);
619627
out = BIO_new(BIO_s_mem());
628+
OPENSSL_assert(out != NULL);
620629
SSL_set_bio(server, in, out);
621630
SSL_set_accept_state(server);
622631

0 commit comments

Comments
 (0)