From 34c967707dcaa1176f993a79774dfff6fd02e2ea Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Mon, 28 Apr 2014 15:49:57 -0400 Subject: [PATCH] improve null checks --- src/switch_core_cert.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/switch_core_cert.c b/src/switch_core_cert.c index 818d560520..6837ff1172 100644 --- a/src/switch_core_cert.c +++ b/src/switch_core_cert.c @@ -289,12 +289,12 @@ SWITCH_DECLARE(int) switch_core_gen_certs(const char *prefix) } } else { - if ((fp = fopen(pvt, "w"))) { + if (pvt && (fp = fopen(pvt, "w"))) { PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL); fclose(fp); } - if ((fp = fopen(rsa, "w"))) { + if (rsa && (fp = fopen(rsa, "w"))) { PEM_write_X509(fp, x509); fclose(fp); } @@ -341,7 +341,10 @@ static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days RSA *rsa; X509_NAME *name=NULL; - if ((pkeyp == NULL) || (*pkeyp == NULL)) { + switch_assert(pkeyp); + switch_assert(x509p); + + if (*pkeyp == NULL) { if ((pk = EVP_PKEY_new()) == NULL) { abort(); } @@ -349,7 +352,7 @@ static int mkcert(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days pk = *pkeyp; } - if ((x509p == NULL) || (*x509p == NULL)) { + if (*x509p == NULL) { if ((x = X509_new()) == NULL) { goto err; }