Continue standardisation of malloc handling in apps

continue on from previous commits but in the apps directory

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
diff --git a/apps/apps.c b/apps/apps.c
index c519ae6..89f4340 100644
--- a/apps/apps.c
+++ b/apps/apps.c
@@ -646,7 +646,7 @@
     if (!bio || !BIO_set_conn_port(bio, port))
         goto err;
     rctx = OCSP_REQ_CTX_new(bio, 1024);
-    if (!rctx)
+    if (rctx == NULL)
         goto err;
     if (!OCSP_REQ_CTX_http(rctx, "GET", path))
         goto err;
@@ -856,7 +856,7 @@
         rsa = d2i_RSAPublicKey_bio(key, NULL);
         if (rsa) {
             pkey = EVP_PKEY_new();
-            if (pkey)
+            if (pkey != NULL)
                 EVP_PKEY_set1_RSA(pkey, rsa);
             RSA_free(rsa);
         } else
@@ -866,9 +866,9 @@
         rsa = PEM_read_bio_RSAPublicKey(key, NULL,
                                         (pem_password_cb *)password_callback,
                                         &cb_data);
-        if (rsa) {
+        if (rsa != NULL) {
             pkey = EVP_PKEY_new();
-            if (pkey)
+            if (pkey != NULL)
                 EVP_PKEY_set1_RSA(pkey, rsa);
             RSA_free(rsa);
         } else
@@ -1252,7 +1252,7 @@
     X509_STORE *store = X509_STORE_new();
     X509_LOOKUP *lookup;
 
-    if (!store)
+    if (store == NULL)
         goto end;
 
     if(CAfile != NULL || !noCAfile) {
@@ -1541,7 +1541,7 @@
     else
         btmp = BN_new();
 
-    if (!btmp)
+    if (btmp == NULL)
         return 0;
 
     if (!BN_pseudo_rand(btmp, SERIAL_RAND_BITS, 0, 0))
@@ -1901,7 +1901,7 @@
     int len, ret;
     unsigned char tbuf[1024];
     mem = BIO_new(BIO_s_mem());
-    if (!mem)
+    if (mem == NULL)
         return -1;
     for (;;) {
         if ((maxlen != -1) && maxlen < 1024)
diff --git a/apps/ca.c b/apps/ca.c
index 691f4e7..eea9d99 100644
--- a/apps/ca.c
+++ b/apps/ca.c
@@ -1165,7 +1165,7 @@
             goto end;
 
         tmptm = ASN1_TIME_new();
-        if (!tmptm)
+        if (tmptm == NULL)
             goto end;
         X509_gmtime_adj(tmptm, 0);
         X509_CRL_set_lastUpdate(crl, tmptm);
@@ -2283,10 +2283,12 @@
     char **rrow, *a_tm_s;
 
     a_tm = ASN1_UTCTIME_new();
+    if (a_tm == NULL)
+        return -1;
 
     /* get actual time and make a string */
     a_tm = X509_gmtime_adj(a_tm, 0);
-    a_tm_s = (char *)OPENSSL_malloc(a_tm->length + 1);
+    a_tm_s = (char *)app_malloc(a_tm->length + 1, "time string");
 
     memcpy(a_tm_s, a_tm->data, a_tm->length);
     a_tm_s[a_tm->length] = '\0';
@@ -2470,7 +2472,7 @@
 
     if (rev && (reason_code != OCSP_REVOKED_STATUS_NOSTATUS)) {
         rtmp = ASN1_ENUMERATED_new();
-        if (!rtmp || !ASN1_ENUMERATED_set(rtmp, reason_code))
+        if (rtmp == NULL || !ASN1_ENUMERATED_set(rtmp, reason_code))
             goto end;
         if (!X509_REVOKED_add1_ext_i2d(rev, NID_crl_reason, rtmp, 0, 0))
             goto end;
@@ -2576,7 +2578,7 @@
 
     if (prevtm) {
         *prevtm = ASN1_UTCTIME_new();
-        if (!*prevtm) {
+        if (*prevtm == NULL) {
             BIO_printf(bio_err, "memory allocation failure\n");
             goto end;
         }
@@ -2622,7 +2624,7 @@
                 goto end;
             }
             comp_time = ASN1_GENERALIZEDTIME_new();
-            if (!comp_time) {
+            if (comp_time == NULL) {
                 BIO_printf(bio_err, "memory allocation failure\n");
                 goto end;
             }
diff --git a/apps/cms.c b/apps/cms.c
index fef3403..14f8f55 100644
--- a/apps/cms.c
+++ b/apps/cms.c
@@ -1269,7 +1269,7 @@
         if (!gen)
             goto err;
         gens = GENERAL_NAMES_new();
-        if (!gens)
+        if (gens == NULL)
             goto err;
         if (!sk_GENERAL_NAME_push(gens, gen))
             goto err;
diff --git a/apps/dhparam.c b/apps/dhparam.c
index 17c0b5b..e794dac 100644
--- a/apps/dhparam.c
+++ b/apps/dhparam.c
@@ -251,7 +251,7 @@
 
         BN_GENCB *cb;
         cb = BN_GENCB_new();
-        if (!cb) {
+        if (cb == NULL) {
             ERR_print_errors(bio_err);
             goto end;
         }
@@ -271,7 +271,7 @@
 
             BIO_printf(bio_err,
                        "Generating DSA parameters, %d bit long prime\n", num);
-            if (!dsa
+            if (dsa == NULL
                 || !DSA_generate_parameters_ex(dsa, num, NULL, 0, NULL, NULL,
                                                cb)) {
                 DSA_free(dsa);
@@ -295,7 +295,7 @@
                        "Generating DH parameters, %d bit long safe prime, generator %d\n",
                        num, g);
             BIO_printf(bio_err, "This is going to take a long time\n");
-            if (!dh || !DH_generate_parameters_ex(dh, num, g, cb)) {
+            if (dh == NULL || !DH_generate_parameters_ex(dh, num, g, cb)) {
                 BN_GENCB_free(cb);
                 ERR_print_errors(bio_err);
                 goto end;
diff --git a/apps/dsaparam.c b/apps/dsaparam.c
index a0a3372..c591b5d 100644
--- a/apps/dsaparam.c
+++ b/apps/dsaparam.c
@@ -208,14 +208,14 @@
 
     if (numbits > 0) {
         cb = BN_GENCB_new();
-        if (!cb) {
+        if (cb == NULL) {
             BIO_printf(bio_err, "Error allocating BN_GENCB object\n");
             goto end;
         }
         BN_GENCB_set(cb, dsa_cb, bio_err);
         assert(need_rand);
         dsa = DSA_new();
-        if (!dsa) {
+        if (dsa == NULL) {
             BIO_printf(bio_err, "Error allocating DSA object\n");
             goto end;
         }
diff --git a/apps/genpkey.c b/apps/genpkey.c
index 333cea9..0156413 100644
--- a/apps/genpkey.c
+++ b/apps/genpkey.c
@@ -269,7 +269,7 @@
     }
 
     ctx = EVP_PKEY_CTX_new(pkey, e);
-    if (!ctx)
+    if (ctx == NULL)
         goto err;
     if (EVP_PKEY_keygen_init(ctx) <= 0)
         goto err;
diff --git a/apps/genrsa.c b/apps/genrsa.c
index b0e5e19..8921197 100644
--- a/apps/genrsa.c
+++ b/apps/genrsa.c
@@ -114,7 +114,7 @@
     char *inrand = NULL, *prog, *hexe, *dece;
     OPTION_CHOICE o;
 
-    if (!bn || !cb)
+    if (bn == NULL || cb == NULL)
         goto end;
 
     BN_GENCB_set(cb, genrsa_cb, bio_err);
@@ -185,7 +185,7 @@
     BIO_printf(bio_err, "Generating RSA private key, %d bit long modulus\n",
                num);
     rsa = e ? RSA_new_method(e) : RSA_new();
-    if (!rsa)
+    if (rsa == NULL)
         goto end;
 
     if (non_fips_allow)
diff --git a/apps/nseq.c b/apps/nseq.c
index e8cf69d..fd63bd8 100644
--- a/apps/nseq.c
+++ b/apps/nseq.c
@@ -118,8 +118,10 @@
 
     if (toseq) {
         seq = NETSCAPE_CERT_SEQUENCE_new();
+        if (seq == NULL)
+            goto end;
         seq->certs = sk_X509_new_null();
-        if (!seq->certs)
+        if (seq->certs == NULL)
             goto end;
         while ((x509 = PEM_read_bio_X509(in, NULL, NULL, NULL)))
             sk_X509_push(seq->certs, x509);
diff --git a/apps/ocsp.c b/apps/ocsp.c
index c599ffb..ef7d62a 100644
--- a/apps/ocsp.c
+++ b/apps/ocsp.c
@@ -783,9 +783,9 @@
         BIO_printf(bio_err, "No issuer certificate specified\n");
         return 0;
     }
-    if (!*req)
+    if (*req == NULL)
         *req = OCSP_REQUEST_new();
-    if (!*req)
+    if (*req == NULL)
         goto err;
     id = OCSP_cert_to_id(cert_id_md, cert, issuer);
     if (!id || !sk_OCSP_CERTID_push(ids, id))
@@ -811,9 +811,9 @@
         BIO_printf(bio_err, "No issuer certificate specified\n");
         return 0;
     }
-    if (!*req)
+    if (*req == NULL)
         *req = OCSP_REQUEST_new();
-    if (!*req)
+    if (*req == NULL)
         goto err;
     iname = X509_get_subject_name(issuer);
     ikey = X509_get0_pubkey_bitstr(issuer);
@@ -824,7 +824,7 @@
     }
     id = OCSP_cert_id_new(cert_id_md, iname, ikey, sno);
     ASN1_INTEGER_free(sno);
-    if (!id || !sk_OCSP_CERTID_push(ids, id))
+    if (id == NULL || !sk_OCSP_CERTID_push(ids, id))
         goto err;
     if (!OCSP_request_add0_id(*req, id))
         goto err;
@@ -1029,7 +1029,7 @@
     return NULL;
 # endif
     bufbio = BIO_new(BIO_f_buffer());
-    if (!bufbio)
+    if (bufbio == NULL)
         goto err;
     acbio = BIO_new(BIO_s_accept());
     if (acbio == NULL
@@ -1220,7 +1220,7 @@
     }
 
     ctx = OCSP_sendreq_new(cbio, path, NULL, -1);
-    if (!ctx)
+    if (ctx == NULL)
         return NULL;
 
     for (i = 0; i < sk_CONF_VALUE_num(headers); i++) {
diff --git a/apps/pkeyutl.c b/apps/pkeyutl.c
index 82ebdee..362415e 100644
--- a/apps/pkeyutl.c
+++ b/apps/pkeyutl.c
@@ -376,7 +376,7 @@
 
     EVP_PKEY_free(pkey);
 
-    if (!ctx)
+    if (ctx == NULL)
         goto end;
 
     switch (pkey_op) {
diff --git a/apps/req.c b/apps/req.c
index 1dcf0f7..5d9231c 100644
--- a/apps/req.c
+++ b/apps/req.c
@@ -1442,7 +1442,7 @@
     } else
         gctx = EVP_PKEY_CTX_new_id(*pkey_type, keygen_engine);
 
-    if (!gctx) {
+    if (gctx == NULL) {
         BIO_puts(bio_err, "Error allocating keygen context\n");
         ERR_print_errors(bio_err);
         return NULL;
diff --git a/apps/s_cb.c b/apps/s_cb.c
index 884b5e1..734d57f 100644
--- a/apps/s_cb.c
+++ b/apps/s_cb.c
@@ -1279,8 +1279,10 @@
 {
     X509_STORE *vfy = NULL, *ch = NULL;
     int rv = 0;
-    if (vfyCApath || vfyCAfile) {
+    if (vfyCApath != NULL || vfyCAfile != NULL) {
         vfy = X509_STORE_new();
+        if (vfy == NULL)
+            goto err;
         if (!X509_STORE_load_locations(vfy, vfyCAfile, vfyCApath))
             goto err;
         add_crls_store(vfy, crls);
@@ -1288,8 +1290,10 @@
         if (crl_download)
             store_setup_crl_download(vfy);
     }
-    if (chCApath || chCAfile) {
+    if (chCApath != NULL || chCAfile != NULL) {
         ch = X509_STORE_new();
+        if (ch == NULL)
+            goto err;
         if (!X509_STORE_load_locations(ch, chCAfile, chCApath))
             goto err;
         SSL_CTX_set1_chain_cert_store(ctx, ch);
diff --git a/apps/s_server.c b/apps/s_server.c
index 4848fbe..33f7dc9 100644
--- a/apps/s_server.c
+++ b/apps/s_server.c
@@ -667,7 +667,7 @@
         goto done;
     }
     req = OCSP_REQUEST_new();
-    if (!req)
+    if (req == NULL)
         goto err;
     id = OCSP_cert_to_id(NULL, x, obj.data.x509);
     X509_free(obj.data.x509);
diff --git a/apps/spkac.c b/apps/spkac.c
index eaeb3c1..9cbe7fe 100644
--- a/apps/spkac.c
+++ b/apps/spkac.c
@@ -189,7 +189,7 @@
 
     spkstr = NCONF_get_string(conf, spksect, spkac);
 
-    if (!spkstr) {
+    if (spkstr == NULL) {
         BIO_printf(bio_err, "Can't find SPKAC called \"%s\"\n", spkac);
         ERR_print_errors(bio_err);
         goto end;
diff --git a/apps/ts.c b/apps/ts.c
index 237dd01..b58703a 100644
--- a/apps/ts.c
+++ b/apps/ts.c
@@ -947,7 +947,7 @@
 
     cert_ctx = X509_STORE_new();
     X509_STORE_set_verify_cb(cert_ctx, verify_cb);
-    if (CApath) {
+    if (CApath != NULL) {
         lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_hash_dir());
         if (lookup == NULL) {
             BIO_printf(bio_err, "memory allocation failure\n");
@@ -960,7 +960,7 @@
         }
     }
 
-    if (CAfile) {
+    if (CAfile != NULL) {
         lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
         if (lookup == NULL) {
             BIO_printf(bio_err, "memory allocation failure\n");
diff --git a/apps/x509.c b/apps/x509.c
index ff1e8cb..7155b33 100644
--- a/apps/x509.c
+++ b/apps/x509.c
@@ -590,7 +590,7 @@
 
         if (sno == NULL) {
             sno = ASN1_INTEGER_new();
-            if (!sno || !rand_serial(NULL, sno))
+            if (sno == NULL || !rand_serial(NULL, sno))
                 goto end;
             if (!X509_set_serialNumber(x, sno))
                 goto end;