]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
improve null checks
authorMichael Jerris <mike@jerris.com>
Mon, 28 Apr 2014 19:49:57 +0000 (15:49 -0400)
committerMichael Jerris <mike@jerris.com>
Mon, 28 Apr 2014 19:49:57 +0000 (15:49 -0400)
src/switch_core_cert.c

index 818d5605206969d4e6f78db9bd715d3981e10e41..6837ff11724cc96ee00ce25b28dbda8424a2b62f 100644 (file)
@@ -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;
                }