diff options
author | inoguchi <> | 2022-04-28 15:29:10 +0000 |
---|---|---|
committer | inoguchi <> | 2022-04-28 15:29:10 +0000 |
commit | c37fc325921f61f01919e11a990439dfd6866d7c (patch) | |
tree | 7178704f4c7003bc0f00668bb3b2f0fdf24a88ac /src/usr.bin/openssl/pkcs12.c | |
parent | 0768ecbc46c069c9198b7cd44c7ce2f0866d968a (diff) | |
download | openbsd-c37fc325921f61f01919e11a990439dfd6866d7c.tar.gz openbsd-c37fc325921f61f01919e11a990439dfd6866d7c.tar.bz2 openbsd-c37fc325921f61f01919e11a990439dfd6866d7c.zip |
Compare pointer value with NULL in openssl(1) pkcs12
ok tb@
Diffstat (limited to 'src/usr.bin/openssl/pkcs12.c')
-rw-r--r-- | src/usr.bin/openssl/pkcs12.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/src/usr.bin/openssl/pkcs12.c b/src/usr.bin/openssl/pkcs12.c index ad71155f17..93924d4b8b 100644 --- a/src/usr.bin/openssl/pkcs12.c +++ b/src/usr.bin/openssl/pkcs12.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: pkcs12.c,v 1.18 2022/03/28 11:02:49 inoguchi Exp $ */ | 1 | /* $OpenBSD: pkcs12.c,v 1.19 2022/04/28 15:29:10 inoguchi Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -556,7 +556,7 @@ pkcs12_main(int argc, char **argv) | |||
556 | goto end; | 556 | goto end; |
557 | } | 557 | } |
558 | 558 | ||
559 | if (pkcs12_config.passarg) { | 559 | if (pkcs12_config.passarg != NULL) { |
560 | if (pkcs12_config.export_cert) | 560 | if (pkcs12_config.export_cert) |
561 | pkcs12_config.passargout = pkcs12_config.passarg; | 561 | pkcs12_config.passargout = pkcs12_config.passarg; |
562 | else | 562 | else |
@@ -567,13 +567,13 @@ pkcs12_main(int argc, char **argv) | |||
567 | BIO_printf(bio_err, "Error getting passwords\n"); | 567 | BIO_printf(bio_err, "Error getting passwords\n"); |
568 | goto end; | 568 | goto end; |
569 | } | 569 | } |
570 | if (!cpass) { | 570 | if (cpass == NULL) { |
571 | if (pkcs12_config.export_cert) | 571 | if (pkcs12_config.export_cert) |
572 | cpass = passout; | 572 | cpass = passout; |
573 | else | 573 | else |
574 | cpass = passin; | 574 | cpass = passin; |
575 | } | 575 | } |
576 | if (cpass) { | 576 | if (cpass != NULL) { |
577 | mpass = cpass; | 577 | mpass = cpass; |
578 | pkcs12_config.noprompt = 1; | 578 | pkcs12_config.noprompt = 1; |
579 | } else { | 579 | } else { |
@@ -581,22 +581,22 @@ pkcs12_main(int argc, char **argv) | |||
581 | mpass = macpass; | 581 | mpass = macpass; |
582 | } | 582 | } |
583 | 583 | ||
584 | if (!pkcs12_config.infile) | 584 | if (pkcs12_config.infile == NULL) |
585 | in = BIO_new_fp(stdin, BIO_NOCLOSE); | 585 | in = BIO_new_fp(stdin, BIO_NOCLOSE); |
586 | else | 586 | else |
587 | in = BIO_new_file(pkcs12_config.infile, "rb"); | 587 | in = BIO_new_file(pkcs12_config.infile, "rb"); |
588 | if (!in) { | 588 | if (in == NULL) { |
589 | BIO_printf(bio_err, "Error opening input file %s\n", | 589 | BIO_printf(bio_err, "Error opening input file %s\n", |
590 | pkcs12_config.infile ? pkcs12_config.infile : "<stdin>"); | 590 | pkcs12_config.infile ? pkcs12_config.infile : "<stdin>"); |
591 | perror(pkcs12_config.infile); | 591 | perror(pkcs12_config.infile); |
592 | goto end; | 592 | goto end; |
593 | } | 593 | } |
594 | 594 | ||
595 | if (!pkcs12_config.outfile) { | 595 | if (pkcs12_config.outfile == NULL) { |
596 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 596 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
597 | } else | 597 | } else |
598 | out = BIO_new_file(pkcs12_config.outfile, "wb"); | 598 | out = BIO_new_file(pkcs12_config.outfile, "wb"); |
599 | if (!out) { | 599 | if (out == NULL) { |
600 | BIO_printf(bio_err, "Error opening output file %s\n", | 600 | BIO_printf(bio_err, "Error opening output file %s\n", |
601 | pkcs12_config.outfile ? pkcs12_config.outfile : "<stdout>"); | 601 | pkcs12_config.outfile ? pkcs12_config.outfile : "<stdout>"); |
602 | perror(pkcs12_config.outfile); | 602 | perror(pkcs12_config.outfile); |
@@ -637,10 +637,10 @@ pkcs12_main(int argc, char **argv) | |||
637 | if (!(pkcs12_config.options & NOCERTS)) { | 637 | if (!(pkcs12_config.options & NOCERTS)) { |
638 | certs = load_certs(bio_err, pkcs12_config.infile, | 638 | certs = load_certs(bio_err, pkcs12_config.infile, |
639 | FORMAT_PEM, NULL, "certificates"); | 639 | FORMAT_PEM, NULL, "certificates"); |
640 | if (!certs) | 640 | if (certs == NULL) |
641 | goto export_end; | 641 | goto export_end; |
642 | 642 | ||
643 | if (key) { | 643 | if (key != NULL) { |
644 | /* Look for matching private key */ | 644 | /* Look for matching private key */ |
645 | for (i = 0; i < sk_X509_num(certs); i++) { | 645 | for (i = 0; i < sk_X509_num(certs); i++) { |
646 | x = sk_X509_value(certs, i); | 646 | x = sk_X509_value(certs, i); |
@@ -654,7 +654,7 @@ pkcs12_main(int argc, char **argv) | |||
654 | break; | 654 | break; |
655 | } | 655 | } |
656 | } | 656 | } |
657 | if (!ucert) { | 657 | if (ucert == NULL) { |
658 | BIO_printf(bio_err, | 658 | BIO_printf(bio_err, |
659 | "No certificate matches private key\n"); | 659 | "No certificate matches private key\n"); |
660 | goto export_end; | 660 | goto export_end; |
@@ -663,11 +663,11 @@ pkcs12_main(int argc, char **argv) | |||
663 | } | 663 | } |
664 | 664 | ||
665 | /* Add any more certificates asked for */ | 665 | /* Add any more certificates asked for */ |
666 | if (pkcs12_config.certfile) { | 666 | if (pkcs12_config.certfile != NULL) { |
667 | STACK_OF(X509) *morecerts = NULL; | 667 | STACK_OF(X509) *morecerts = NULL; |
668 | if (!(morecerts = load_certs(bio_err, | 668 | if ((morecerts = load_certs(bio_err, |
669 | pkcs12_config.certfile, FORMAT_PEM, NULL, | 669 | pkcs12_config.certfile, FORMAT_PEM, NULL, |
670 | "certificates from certfile"))) | 670 | "certificates from certfile")) == NULL) |
671 | goto export_end; | 671 | goto export_end; |
672 | while (sk_X509_num(morecerts) > 0) | 672 | while (sk_X509_num(morecerts) > 0) |
673 | sk_X509_push(certs, sk_X509_shift(morecerts)); | 673 | sk_X509_push(certs, sk_X509_shift(morecerts)); |
@@ -680,7 +680,7 @@ pkcs12_main(int argc, char **argv) | |||
680 | int vret; | 680 | int vret; |
681 | STACK_OF(X509) *chain2; | 681 | STACK_OF(X509) *chain2; |
682 | X509_STORE *store = X509_STORE_new(); | 682 | X509_STORE *store = X509_STORE_new(); |
683 | if (!store) { | 683 | if (store == NULL) { |
684 | BIO_printf(bio_err, | 684 | BIO_printf(bio_err, |
685 | "Memory allocation error\n"); | 685 | "Memory allocation error\n"); |
686 | goto export_end; | 686 | goto export_end; |
@@ -720,12 +720,12 @@ pkcs12_main(int argc, char **argv) | |||
720 | X509_alias_set1(sk_X509_value(certs, i), catmp, -1); | 720 | X509_alias_set1(sk_X509_value(certs, i), catmp, -1); |
721 | } | 721 | } |
722 | 722 | ||
723 | if (pkcs12_config.csp_name && key) | 723 | if (pkcs12_config.csp_name != NULL && key != NULL) |
724 | EVP_PKEY_add1_attr_by_NID(key, NID_ms_csp_name, | 724 | EVP_PKEY_add1_attr_by_NID(key, NID_ms_csp_name, |
725 | MBSTRING_ASC, | 725 | MBSTRING_ASC, |
726 | (unsigned char *) pkcs12_config.csp_name, -1); | 726 | (unsigned char *) pkcs12_config.csp_name, -1); |
727 | 727 | ||
728 | if (pkcs12_config.add_lmk && key) | 728 | if (pkcs12_config.add_lmk && key != NULL) |
729 | EVP_PKEY_add1_attr_by_NID(key, NID_LocalKeySet, 0, NULL, | 729 | EVP_PKEY_add1_attr_by_NID(key, NID_LocalKeySet, 0, NULL, |
730 | -1); | 730 | -1); |
731 | 731 | ||
@@ -743,13 +743,13 @@ pkcs12_main(int argc, char **argv) | |||
743 | certs, pkcs12_config.key_pbe, pkcs12_config.cert_pbe, | 743 | certs, pkcs12_config.key_pbe, pkcs12_config.cert_pbe, |
744 | pkcs12_config.iter, -1, pkcs12_config.keytype); | 744 | pkcs12_config.iter, -1, pkcs12_config.keytype); |
745 | 745 | ||
746 | if (!p12) { | 746 | if (p12 == NULL) { |
747 | ERR_print_errors(bio_err); | 747 | ERR_print_errors(bio_err); |
748 | goto export_end; | 748 | goto export_end; |
749 | } | 749 | } |
750 | if (pkcs12_config.macalg) { | 750 | if (pkcs12_config.macalg != NULL) { |
751 | macmd = EVP_get_digestbyname(pkcs12_config.macalg); | 751 | macmd = EVP_get_digestbyname(pkcs12_config.macalg); |
752 | if (!macmd) { | 752 | if (macmd == NULL) { |
753 | BIO_printf(bio_err, | 753 | BIO_printf(bio_err, |
754 | "Unknown digest algorithm %s\n", | 754 | "Unknown digest algorithm %s\n", |
755 | pkcs12_config.macalg); | 755 | pkcs12_config.macalg); |
@@ -771,7 +771,7 @@ pkcs12_main(int argc, char **argv) | |||
771 | goto end; | 771 | goto end; |
772 | 772 | ||
773 | } | 773 | } |
774 | if (!(p12 = d2i_PKCS12_bio(in, NULL))) { | 774 | if ((p12 = d2i_PKCS12_bio(in, NULL)) == NULL) { |
775 | ERR_print_errors(bio_err); | 775 | ERR_print_errors(bio_err); |
776 | goto end; | 776 | goto end; |
777 | } | 777 | } |
@@ -784,7 +784,7 @@ pkcs12_main(int argc, char **argv) | |||
784 | if (!pkcs12_config.twopass) | 784 | if (!pkcs12_config.twopass) |
785 | strlcpy(macpass, pass, sizeof macpass); | 785 | strlcpy(macpass, pass, sizeof macpass); |
786 | 786 | ||
787 | if ((pkcs12_config.options & INFO) && p12->mac) | 787 | if ((pkcs12_config.options & INFO) && p12->mac != NULL) |
788 | BIO_printf(bio_err, "MAC Iteration %ld\n", | 788 | BIO_printf(bio_err, "MAC Iteration %ld\n", |
789 | p12->mac->iter ? ASN1_INTEGER_get(p12->mac->iter) : 1); | 789 | p12->mac->iter ? ASN1_INTEGER_get(p12->mac->iter) : 1); |
790 | if (pkcs12_config.macver) { | 790 | if (pkcs12_config.macver) { |
@@ -829,7 +829,7 @@ dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen, int options, | |||
829 | int ret = 0; | 829 | int ret = 0; |
830 | PKCS7 *p7; | 830 | PKCS7 *p7; |
831 | 831 | ||
832 | if (!(asafes = PKCS12_unpack_authsafes(p12))) | 832 | if ((asafes = PKCS12_unpack_authsafes(p12)) == NULL) |
833 | return 0; | 833 | return 0; |
834 | for (i = 0; i < sk_PKCS7_num(asafes); i++) { | 834 | for (i = 0; i < sk_PKCS7_num(asafes); i++) { |
835 | p7 = sk_PKCS7_value(asafes, i); | 835 | p7 = sk_PKCS7_value(asafes, i); |
@@ -847,7 +847,7 @@ dump_certs_keys_p12(BIO *out, PKCS12 *p12, char *pass, int passlen, int options, | |||
847 | bags = PKCS12_unpack_p7encdata(p7, pass, passlen); | 847 | bags = PKCS12_unpack_p7encdata(p7, pass, passlen); |
848 | } else | 848 | } else |
849 | continue; | 849 | continue; |
850 | if (!bags) | 850 | if (bags == NULL) |
851 | goto err; | 851 | goto err; |
852 | if (!dump_certs_pkeys_bags(out, bags, pass, passlen, | 852 | if (!dump_certs_pkeys_bags(out, bags, pass, passlen, |
853 | options, pempass)) { | 853 | options, pempass)) { |
@@ -915,9 +915,9 @@ dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, int passlen, | |||
915 | if (options & NOKEYS) | 915 | if (options & NOKEYS) |
916 | return 1; | 916 | return 1; |
917 | print_attribs(out, bag->attrib, "Bag Attributes"); | 917 | print_attribs(out, bag->attrib, "Bag Attributes"); |
918 | if (!(p8 = PKCS12_decrypt_skey(bag, pass, passlen))) | 918 | if ((p8 = PKCS12_decrypt_skey(bag, pass, passlen)) == NULL) |
919 | return 0; | 919 | return 0; |
920 | if (!(pkey = EVP_PKCS82PKEY(p8))) { | 920 | if ((pkey = EVP_PKCS82PKEY(p8)) == NULL) { |
921 | PKCS8_PRIV_KEY_INFO_free(p8); | 921 | PKCS8_PRIV_KEY_INFO_free(p8); |
922 | return 0; | 922 | return 0; |
923 | } | 923 | } |
@@ -933,7 +933,7 @@ dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, int passlen, | |||
933 | BIO_printf(bio_err, "Certificate bag\n"); | 933 | BIO_printf(bio_err, "Certificate bag\n"); |
934 | if (options & NOCERTS) | 934 | if (options & NOCERTS) |
935 | return 1; | 935 | return 1; |
936 | if (PKCS12_get_attr(bag, NID_localKeyID)) { | 936 | if (PKCS12_get_attr(bag, NID_localKeyID) != NULL) { |
937 | if (options & CACERTS) | 937 | if (options & CACERTS) |
938 | return 1; | 938 | return 1; |
939 | } else if (options & CLCERTS) | 939 | } else if (options & CLCERTS) |
@@ -941,7 +941,7 @@ dump_certs_pkeys_bag(BIO *out, PKCS12_SAFEBAG *bag, char *pass, int passlen, | |||
941 | print_attribs(out, bag->attrib, "Bag Attributes"); | 941 | print_attribs(out, bag->attrib, "Bag Attributes"); |
942 | if (OBJ_obj2nid(bag->value.bag->type) != NID_x509Certificate) | 942 | if (OBJ_obj2nid(bag->value.bag->type) != NID_x509Certificate) |
943 | return 1; | 943 | return 1; |
944 | if (!(x509 = PKCS12_certbag2x509(bag))) | 944 | if ((x509 = PKCS12_certbag2x509(bag)) == NULL) |
945 | return 0; | 945 | return 0; |
946 | dump_cert_text(out, x509); | 946 | dump_cert_text(out, x509); |
947 | PEM_write_bio_X509(out, x509); | 947 | PEM_write_bio_X509(out, x509); |
@@ -999,7 +999,7 @@ alg_print(BIO *x, const X509_ALGOR *alg) | |||
999 | 999 | ||
1000 | p = alg->parameter->value.sequence->data; | 1000 | p = alg->parameter->value.sequence->data; |
1001 | pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length); | 1001 | pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length); |
1002 | if (!pbe) | 1002 | if (pbe == NULL) |
1003 | return 1; | 1003 | return 1; |
1004 | BIO_printf(bio_err, "%s, Iteration %ld\n", | 1004 | BIO_printf(bio_err, "%s, Iteration %ld\n", |
1005 | OBJ_nid2ln(OBJ_obj2nid(alg->algorithm)), | 1005 | OBJ_nid2ln(OBJ_obj2nid(alg->algorithm)), |
@@ -1050,7 +1050,7 @@ print_attribs(BIO *out, const STACK_OF(X509_ATTRIBUTE) *attrlst, | |||
1050 | ASN1_TYPE *av; | 1050 | ASN1_TYPE *av; |
1051 | int i, j, attr_nid; | 1051 | int i, j, attr_nid; |
1052 | 1052 | ||
1053 | if (!attrlst) { | 1053 | if (attrlst == NULL) { |
1054 | BIO_printf(out, "%s: <No Attributes>\n", name); | 1054 | BIO_printf(out, "%s: <No Attributes>\n", name); |
1055 | return 1; | 1055 | return 1; |
1056 | } | 1056 | } |
@@ -1095,7 +1095,7 @@ hex_prin(BIO *out, unsigned char *buf, int len) | |||
1095 | static int | 1095 | static int |
1096 | set_pbe(BIO *err, int *ppbe, const char *str) | 1096 | set_pbe(BIO *err, int *ppbe, const char *str) |
1097 | { | 1097 | { |
1098 | if (!str) | 1098 | if (str == NULL) |
1099 | return 0; | 1099 | return 0; |
1100 | if (!strcmp(str, "NONE")) { | 1100 | if (!strcmp(str, "NONE")) { |
1101 | *ppbe = -1; | 1101 | *ppbe = -1; |