Skip to content

Commit 0dd40cf

Browse files
author
inoguchi
committed
Compare pointer value with NULL
1 parent cf4fa22 commit 0dd40cf

File tree

1 file changed

+63
-63
lines changed
  • src/usr.bin/openssl

1 file changed

+63
-63
lines changed

src/usr.bin/openssl/ts.c

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ts.c,v 1.20 2022/03/24 12:00:17 inoguchi Exp $ */
1+
/* $OpenBSD: ts.c,v 1.21 2022/03/24 13:47:55 inoguchi Exp $ */
22
/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
33
* project 2002.
44
*/
@@ -391,7 +391,7 @@ ts_main(int argc, char **argv)
391391
goto usage;
392392

393393
/* Get the password if required. */
394-
if (ts_config.mode == CMD_REPLY && ts_config.passin &&
394+
if (ts_config.mode == CMD_REPLY && ts_config.passin != NULL &&
395395
!app_passwd(bio_err, ts_config.passin, NULL, &password, NULL)) {
396396
BIO_printf(bio_err, "Error getting password.\n");
397397
goto cleanup;
@@ -439,12 +439,12 @@ ts_main(int argc, char **argv)
439439
ts_config.token_out, ts_config.text);
440440
break;
441441
case CMD_VERIFY:
442-
ret = !(((ts_config.queryfile && !ts_config.data &&
443-
!ts_config.digest) ||
444-
(!ts_config.queryfile && ts_config.data &&
445-
!ts_config.digest) ||
446-
(!ts_config.queryfile && !ts_config.data &&
447-
ts_config.digest)) &&
442+
ret = !(((ts_config.queryfile != NULL && ts_config.data == NULL &&
443+
ts_config.digest == NULL) ||
444+
(ts_config.queryfile == NULL && ts_config.data != NULL &&
445+
ts_config.digest == NULL) ||
446+
(ts_config.queryfile == NULL && ts_config.data == NULL &&
447+
ts_config.digest != NULL)) &&
448448
ts_config.in != NULL);
449449
if (ret)
450450
goto usage;
@@ -477,7 +477,7 @@ txt2obj(const char *oid)
477477
{
478478
ASN1_OBJECT *oid_obj = NULL;
479479

480-
if (!(oid_obj = OBJ_txt2obj(oid, 0)))
480+
if ((oid_obj = OBJ_txt2obj(oid, 0)) == NULL)
481481
BIO_printf(bio_err, "cannot convert %s to OID\n", oid);
482482

483483
return oid_obj;
@@ -489,11 +489,11 @@ load_config_file(const char *configfile)
489489
CONF *conf = NULL;
490490
long errorline = -1;
491491

492-
if (!configfile)
492+
if (configfile == NULL)
493493
configfile = getenv("OPENSSL_CONF");
494494

495-
if (configfile &&
496-
(!(conf = NCONF_new(NULL)) ||
495+
if (configfile != NULL &&
496+
((conf = NCONF_new(NULL)) == NULL ||
497497
NCONF_load(conf, configfile, &errorline) <= 0)) {
498498
if (errorline <= 0)
499499
BIO_printf(bio_err, "error loading the config file "
@@ -510,7 +510,7 @@ load_config_file(const char *configfile)
510510
p = NCONF_get_string(conf, NULL, ENV_OID_FILE);
511511
if (p != NULL) {
512512
BIO *oid_bio = BIO_new_file(p, "r");
513-
if (!oid_bio)
513+
if (oid_bio == NULL)
514514
ERR_print_errors(bio_err);
515515
else {
516516
OBJ_create_objects(oid_bio);
@@ -546,8 +546,8 @@ query_command(const char *data, char *digest, const EVP_MD *md,
546546
query = d2i_TS_REQ_bio(in_bio, NULL);
547547
} else {
548548
/* Open the file if no explicit digest bytes were specified. */
549-
if (!digest &&
550-
!(data_bio = BIO_open_with_default(data, "rb", stdin)))
549+
if (digest == NULL &&
550+
(data_bio = BIO_open_with_default(data, "rb", stdin)) == NULL)
551551
goto end;
552552
/* Creating the query object. */
553553
query = create_query(data_bio, digest, md,
@@ -605,27 +605,27 @@ create_query(BIO *data_bio, char *digest, const EVP_MD *md, const char *policy,
605605
ASN1_INTEGER *nonce_asn1 = NULL;
606606

607607
/* Setting default message digest. */
608-
if (!md && !(md = EVP_get_digestbyname("sha1")))
608+
if (md == NULL && (md = EVP_get_digestbyname("sha1")) == NULL)
609609
goto err;
610610

611611
/* Creating request object. */
612-
if (!(ts_req = TS_REQ_new()))
612+
if ((ts_req = TS_REQ_new()) == NULL)
613613
goto err;
614614

615615
/* Setting version. */
616616
if (!TS_REQ_set_version(ts_req, 1))
617617
goto err;
618618

619619
/* Creating and adding MSG_IMPRINT object. */
620-
if (!(msg_imprint = TS_MSG_IMPRINT_new()))
620+
if ((msg_imprint = TS_MSG_IMPRINT_new()) == NULL)
621621
goto err;
622622

623623
/* Adding algorithm. */
624-
if (!(algo = X509_ALGOR_new()))
624+
if ((algo = X509_ALGOR_new()) == NULL)
625625
goto err;
626-
if (!(algo->algorithm = OBJ_nid2obj(EVP_MD_type(md))))
626+
if ((algo->algorithm = OBJ_nid2obj(EVP_MD_type(md))) == NULL)
627627
goto err;
628-
if (!(algo->parameter = ASN1_TYPE_new()))
628+
if ((algo->parameter = ASN1_TYPE_new()) == NULL)
629629
goto err;
630630
algo->parameter->type = V_ASN1_NULL;
631631
if (!TS_MSG_IMPRINT_set_algo(msg_imprint, algo))
@@ -641,15 +641,15 @@ create_query(BIO *data_bio, char *digest, const EVP_MD *md, const char *policy,
641641
goto err;
642642

643643
/* Setting policy if requested. */
644-
if (policy && !(policy_obj = txt2obj(policy)))
644+
if (policy != NULL && (policy_obj = txt2obj(policy)) == NULL)
645645
goto err;
646-
if (policy_obj && !TS_REQ_set_policy_id(ts_req, policy_obj))
646+
if (policy_obj != NULL && !TS_REQ_set_policy_id(ts_req, policy_obj))
647647
goto err;
648648

649649
/* Setting nonce if requested. */
650-
if (!no_nonce && !(nonce_asn1 = create_nonce(NONCE_LENGTH)))
650+
if (!no_nonce && (nonce_asn1 = create_nonce(NONCE_LENGTH)) == NULL)
651651
goto err;
652-
if (nonce_asn1 && !TS_REQ_set_nonce(ts_req, nonce_asn1))
652+
if (nonce_asn1 != NULL && !TS_REQ_set_nonce(ts_req, nonce_asn1))
653653
goto err;
654654

655655
/* Setting certificate request flag if requested. */
@@ -682,7 +682,7 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
682682
md_value_len = EVP_MD_size(md);
683683
if (md_value_len < 0)
684684
goto err;
685-
if (input) {
685+
if (input != NULL) {
686686
/* Digest must be computed from an input file. */
687687
EVP_MD_CTX *md_ctx;
688688
unsigned char buffer[4096];
@@ -706,7 +706,7 @@ create_digest(BIO *input, char *digest, const EVP_MD *md,
706706
/* Digest bytes are specified with digest. */
707707
long digest_len;
708708
*md_value = string_to_hex(digest, &digest_len);
709-
if (!*md_value || md_value_len != digest_len) {
709+
if (*md_value == NULL || md_value_len != digest_len) {
710710
free(*md_value);
711711
*md_value = NULL;
712712
BIO_printf(bio_err, "bad digest, %d bytes "
@@ -736,12 +736,12 @@ create_nonce(int bits)
736736
/* Find the first non-zero byte and creating ASN1_INTEGER object. */
737737
for (i = 0; i < len && !buf[i]; ++i)
738738
;
739-
if (!(nonce = ASN1_INTEGER_new()))
739+
if ((nonce = ASN1_INTEGER_new()) == NULL)
740740
goto err;
741741
free(nonce->data);
742742
/* Allocate at least one byte. */
743743
nonce->length = len - i;
744-
if (!(nonce->data = malloc(nonce->length + 1)))
744+
if ((nonce->data = malloc(nonce->length + 1)) == NULL)
745745
goto err;
746746
memcpy(nonce->data, buf + i, nonce->length);
747747

@@ -785,10 +785,9 @@ reply_command(CONF *conf, char *section, char *queryfile, char *passin,
785785
response = d2i_TS_RESP_bio(in_bio, NULL);
786786
}
787787
} else {
788-
response = create_response(conf, section, queryfile,
789-
passin, inkey, signer, chain,
790-
policy);
791-
if (response)
788+
response = create_response(conf, section, queryfile, passin,
789+
inkey, signer, chain, policy);
790+
if (response != NULL)
792791
BIO_printf(bio_err, "Response has been generated.\n");
793792
else
794793
BIO_printf(bio_err, "Response is not generated.\n");
@@ -848,17 +847,17 @@ read_PKCS7(BIO *in_bio)
848847
TS_STATUS_INFO *si = NULL;
849848

850849
/* Read PKCS7 object and extract the signed time stamp info. */
851-
if (!(token = d2i_PKCS7_bio(in_bio, NULL)))
850+
if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL)
852851
goto end;
853-
if (!(tst_info = PKCS7_to_TS_TST_INFO(token)))
852+
if ((tst_info = PKCS7_to_TS_TST_INFO(token)) == NULL)
854853
goto end;
855854

856855
/* Creating response object. */
857-
if (!(resp = TS_RESP_new()))
856+
if ((resp = TS_RESP_new()) == NULL)
858857
goto end;
859858

860859
/* Create granted status info. */
861-
if (!(si = TS_STATUS_INFO_new()))
860+
if ((si = TS_STATUS_INFO_new()) == NULL)
862861
goto end;
863862
if (!(ASN1_INTEGER_set(si->status, TS_STATUS_GRANTED)))
864863
goto end;
@@ -891,15 +890,15 @@ create_response(CONF *conf, const char *section, char *queryfile, char *passin,
891890
BIO *query_bio = NULL;
892891
TS_RESP_CTX *resp_ctx = NULL;
893892

894-
if (!(query_bio = BIO_new_file(queryfile, "rb")))
893+
if ((query_bio = BIO_new_file(queryfile, "rb")) == NULL)
895894
goto end;
896895

897896
/* Getting TSA configuration section. */
898-
if (!(section = TS_CONF_get_tsa_section(conf, section)))
897+
if ((section = TS_CONF_get_tsa_section(conf, section)) == NULL)
899898
goto end;
900899

901900
/* Setting up response generation context. */
902-
if (!(resp_ctx = TS_RESP_CTX_new()))
901+
if ((resp_ctx = TS_RESP_CTX_new()) == NULL)
903902
goto end;
904903

905904
/* Setting serial number provider callback. */
@@ -951,7 +950,7 @@ create_response(CONF *conf, const char *section, char *queryfile, char *passin,
951950
goto end;
952951

953952
/* Creating the response. */
954-
if (!(response = TS_RESP_create_response(resp_ctx, query_bio)))
953+
if ((response = TS_RESP_create_response(resp_ctx, query_bio)) == NULL)
955954
goto end;
956955

957956
ret = 1;
@@ -972,7 +971,7 @@ serial_cb(TS_RESP_CTX *ctx, void *data)
972971
const char *serial_file = (const char *) data;
973972
ASN1_INTEGER *serial = next_serial(serial_file);
974973

975-
if (!serial) {
974+
if (serial == NULL) {
976975
TS_RESP_CTX_set_status_info(ctx, TS_STATUS_REJECTION,
977976
"Error during serial number "
978977
"generation.");
@@ -992,10 +991,10 @@ next_serial(const char *serialfile)
992991
ASN1_INTEGER *serial = NULL;
993992
BIGNUM *bn = NULL;
994993

995-
if (!(serial = ASN1_INTEGER_new()))
994+
if ((serial = ASN1_INTEGER_new()) == NULL)
996995
goto err;
997996

998-
if (!(in = BIO_new_file(serialfile, "r"))) {
997+
if ((in = BIO_new_file(serialfile, "r")) == NULL) {
999998
ERR_clear_error();
1000999
BIO_printf(bio_err, "Warning: could not open file %s for "
10011000
"reading, using serial number: 1\n", serialfile);
@@ -1008,13 +1007,13 @@ next_serial(const char *serialfile)
10081007
serialfile);
10091008
goto err;
10101009
}
1011-
if (!(bn = ASN1_INTEGER_to_BN(serial, NULL)))
1010+
if ((bn = ASN1_INTEGER_to_BN(serial, NULL)) == NULL)
10121011
goto err;
10131012
ASN1_INTEGER_free(serial);
10141013
serial = NULL;
10151014
if (!BN_add_word(bn, 1))
10161015
goto err;
1017-
if (!(serial = BN_to_ASN1_INTEGER(bn, NULL)))
1016+
if ((serial = BN_to_ASN1_INTEGER(bn, NULL)) == NULL)
10181017
goto err;
10191018
}
10201019
ret = 1;
@@ -1034,7 +1033,7 @@ save_ts_serial(const char *serialfile, ASN1_INTEGER *serial)
10341033
int ret = 0;
10351034
BIO *out = NULL;
10361035

1037-
if (!(out = BIO_new_file(serialfile, "w")))
1036+
if ((out = BIO_new_file(serialfile, "w")) == NULL)
10381037
goto err;
10391038
if (i2a_ASN1_INTEGER(out, serial) <= 0)
10401039
goto err;
@@ -1064,18 +1063,18 @@ verify_command(char *data, char *digest, char *queryfile, char *in,
10641063
int ret = 0;
10651064

10661065
/* Decode the token (PKCS7) or response (TS_RESP) files. */
1067-
if (!(in_bio = BIO_new_file(in, "rb")))
1066+
if ((in_bio = BIO_new_file(in, "rb")) == NULL)
10681067
goto end;
10691068
if (token_in) {
1070-
if (!(token = d2i_PKCS7_bio(in_bio, NULL)))
1069+
if ((token = d2i_PKCS7_bio(in_bio, NULL)) == NULL)
10711070
goto end;
10721071
} else {
1073-
if (!(response = d2i_TS_RESP_bio(in_bio, NULL)))
1072+
if ((response = d2i_TS_RESP_bio(in_bio, NULL)) == NULL)
10741073
goto end;
10751074
}
10761075

1077-
if (!(verify_ctx = create_verify_ctx(data, digest, queryfile,
1078-
ca_path, ca_file, untrusted)))
1076+
if ((verify_ctx = create_verify_ctx(data, digest, queryfile,
1077+
ca_path, ca_file, untrusted)) == NULL)
10791078
goto end;
10801079

10811080
/* Checking the token or response against the request. */
@@ -1111,18 +1110,18 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
11111110
int ret = 0;
11121111

11131112
if (data != NULL || digest != NULL) {
1114-
if (!(ctx = TS_VERIFY_CTX_new()))
1113+
if ((ctx = TS_VERIFY_CTX_new()) == NULL)
11151114
goto err;
11161115
ctx->flags = TS_VFY_VERSION | TS_VFY_SIGNER;
11171116
if (data != NULL) {
11181117
ctx->flags |= TS_VFY_DATA;
1119-
if (!(ctx->data = BIO_new_file(data, "rb")))
1118+
if ((ctx->data = BIO_new_file(data, "rb")) == NULL)
11201119
goto err;
11211120
} else if (digest != NULL) {
11221121
long imprint_len;
11231122
ctx->flags |= TS_VFY_IMPRINT;
1124-
if (!(ctx->imprint = string_to_hex(digest,
1125-
&imprint_len))) {
1123+
if ((ctx->imprint = string_to_hex(digest,
1124+
&imprint_len)) == NULL) {
11261125
BIO_printf(bio_err, "invalid digest string\n");
11271126
goto err;
11281127
}
@@ -1133,11 +1132,11 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
11331132
* The request has just to be read, decoded and converted to
11341133
* a verify context object.
11351134
*/
1136-
if (!(input = BIO_new_file(queryfile, "rb")))
1135+
if ((input = BIO_new_file(queryfile, "rb")) == NULL)
11371136
goto err;
1138-
if (!(request = d2i_TS_REQ_bio(input, NULL)))
1137+
if ((request = d2i_TS_REQ_bio(input, NULL)) == NULL)
11391138
goto err;
1140-
if (!(ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)))
1139+
if ((ctx = TS_REQ_to_TS_VERIFY_CTX(request, NULL)) == NULL)
11411140
goto err;
11421141
} else
11431142
return NULL;
@@ -1146,11 +1145,12 @@ create_verify_ctx(char *data, char *digest, char *queryfile, char *ca_path,
11461145
ctx->flags |= TS_VFY_SIGNATURE;
11471146

11481147
/* Initialising the X509_STORE object. */
1149-
if (!(ctx->store = create_cert_store(ca_path, ca_file)))
1148+
if ((ctx->store = create_cert_store(ca_path, ca_file)) == NULL)
11501149
goto err;
11511150

11521151
/* Loading untrusted certificates. */
1153-
if (untrusted && !(ctx->certs = TS_CONF_load_certs(untrusted)))
1152+
if (untrusted != NULL &&
1153+
(ctx->certs = TS_CONF_load_certs(untrusted)) == NULL)
11541154
goto err;
11551155

11561156
ret = 1;
@@ -1178,7 +1178,7 @@ create_cert_store(char *ca_path, char *ca_file)
11781178
X509_STORE_set_verify_cb(cert_ctx, verify_cb);
11791179

11801180
/* Adding a trusted certificate directory source. */
1181-
if (ca_path) {
1181+
if (ca_path != NULL) {
11821182
lookup = X509_STORE_add_lookup(cert_ctx,
11831183
X509_LOOKUP_hash_dir());
11841184
if (lookup == NULL) {
@@ -1193,7 +1193,7 @@ create_cert_store(char *ca_path, char *ca_file)
11931193
}
11941194
}
11951195
/* Adding a trusted certificate file source. */
1196-
if (ca_file) {
1196+
if (ca_file != NULL) {
11971197
lookup = X509_STORE_add_lookup(cert_ctx, X509_LOOKUP_file());
11981198
if (lookup == NULL) {
11991199
BIO_printf(bio_err, "memory allocation failure\n");

0 commit comments

Comments
 (0)