diff options
author | inoguchi <> | 2022-01-11 15:45:00 +0000 |
---|---|---|
committer | inoguchi <> | 2022-01-11 15:45:00 +0000 |
commit | d9052f84c6db2f82bf6c973587ca6b90955b1acf (patch) | |
tree | 4691a6689762b3c9ec44c4756f9b1bd3eea3099d /src | |
parent | 4750a69f6750a96b666bda88a18e68720015a6ea (diff) | |
download | openbsd-d9052f84c6db2f82bf6c973587ca6b90955b1acf.tar.gz openbsd-d9052f84c6db2f82bf6c973587ca6b90955b1acf.tar.bz2 openbsd-d9052f84c6db2f82bf6c973587ca6b90955b1acf.zip |
Check function return value
Diffstat (limited to 'src')
-rw-r--r-- | src/usr.bin/openssl/smime.c | 89 |
1 files changed, 57 insertions, 32 deletions
diff --git a/src/usr.bin/openssl/smime.c b/src/usr.bin/openssl/smime.c index 323bdc199f..9b8ffc2d33 100644 --- a/src/usr.bin/openssl/smime.c +++ b/src/usr.bin/openssl/smime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: smime.c,v 1.14 2022/01/11 15:05:58 inoguchi Exp $ */ | 1 | /* $OpenBSD: smime.c,v 1.15 2022/01/11 15:45:00 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 | */ |
@@ -751,14 +751,20 @@ smime_main(int argc, char **argv) | |||
751 | goto argerr; | 751 | goto argerr; |
752 | } | 752 | } |
753 | if (smime_config.signerfile != NULL) { | 753 | if (smime_config.signerfile != NULL) { |
754 | if (smime_config.sksigners == NULL) | 754 | if (smime_config.sksigners == NULL) { |
755 | smime_config.sksigners = sk_OPENSSL_STRING_new_null(); | 755 | if ((smime_config.sksigners = sk_OPENSSL_STRING_new_null()) == NULL) |
756 | sk_OPENSSL_STRING_push(smime_config.sksigners, smime_config.signerfile); | 756 | goto end; |
757 | if (smime_config.skkeys == NULL) | 757 | } |
758 | smime_config.skkeys = sk_OPENSSL_STRING_new_null(); | 758 | if (!sk_OPENSSL_STRING_push(smime_config.sksigners, smime_config.signerfile)) |
759 | goto end; | ||
760 | if (smime_config.skkeys == NULL) { | ||
761 | if ((smime_config.skkeys = sk_OPENSSL_STRING_new_null()) == NULL) | ||
762 | goto end; | ||
763 | } | ||
759 | if (smime_config.keyfile == NULL) | 764 | if (smime_config.keyfile == NULL) |
760 | smime_config.keyfile = smime_config.signerfile; | 765 | smime_config.keyfile = smime_config.signerfile; |
761 | sk_OPENSSL_STRING_push(smime_config.skkeys, smime_config.keyfile); | 766 | if (!sk_OPENSSL_STRING_push(smime_config.skkeys, smime_config.keyfile)) |
767 | goto end; | ||
762 | } | 768 | } |
763 | if (smime_config.sksigners == NULL) { | 769 | if (smime_config.sksigners == NULL) { |
764 | BIO_printf(bio_err, "No signer certificate specified\n"); | 770 | BIO_printf(bio_err, "No signer certificate specified\n"); |
@@ -776,8 +782,9 @@ smime_main(int argc, char **argv) | |||
776 | BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n"); | 782 | BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n"); |
777 | badarg = 1; | 783 | badarg = 1; |
778 | } | 784 | } |
779 | } else if (!smime_config.operation) | 785 | } else if (!smime_config.operation) { |
780 | badarg = 1; | 786 | badarg = 1; |
787 | } | ||
781 | 788 | ||
782 | if (badarg) { | 789 | if (badarg) { |
783 | argerr: | 790 | argerr: |
@@ -819,13 +826,15 @@ smime_main(int argc, char **argv) | |||
819 | goto end; | 826 | goto end; |
820 | #endif | 827 | #endif |
821 | } | 828 | } |
822 | encerts = sk_X509_new_null(); | 829 | if ((encerts = sk_X509_new_null()) == NULL) |
830 | goto end; | ||
823 | while (*args != NULL) { | 831 | while (*args != NULL) { |
824 | if ((cert = load_cert(bio_err, *args, FORMAT_PEM, | 832 | if ((cert = load_cert(bio_err, *args, FORMAT_PEM, |
825 | NULL, "recipient certificate file")) == NULL) { | 833 | NULL, "recipient certificate file")) == NULL) { |
826 | goto end; | 834 | goto end; |
827 | } | 835 | } |
828 | sk_X509_push(encerts, cert); | 836 | if (!sk_X509_push(encerts, cert)) |
837 | goto end; | ||
829 | cert = NULL; | 838 | cert = NULL; |
830 | args++; | 839 | args++; |
831 | } | 840 | } |
@@ -850,8 +859,9 @@ smime_main(int argc, char **argv) | |||
850 | } else if (smime_config.operation == SMIME_SIGN) { | 859 | } else if (smime_config.operation == SMIME_SIGN) { |
851 | if (smime_config.keyfile == NULL) | 860 | if (smime_config.keyfile == NULL) |
852 | smime_config.keyfile = smime_config.signerfile; | 861 | smime_config.keyfile = smime_config.signerfile; |
853 | } else | 862 | } else { |
854 | smime_config.keyfile = NULL; | 863 | smime_config.keyfile = NULL; |
864 | } | ||
855 | 865 | ||
856 | if (smime_config.keyfile != NULL) { | 866 | if (smime_config.keyfile != NULL) { |
857 | key = load_key(bio_err, smime_config.keyfile, smime_config.keyform, 0, passin, | 867 | key = load_key(bio_err, smime_config.keyfile, smime_config.keyform, 0, passin, |
@@ -865,8 +875,10 @@ smime_main(int argc, char **argv) | |||
865 | "Can't open input file %s\n", smime_config.infile); | 875 | "Can't open input file %s\n", smime_config.infile); |
866 | goto end; | 876 | goto end; |
867 | } | 877 | } |
868 | } else | 878 | } else { |
869 | in = BIO_new_fp(stdin, BIO_NOCLOSE); | 879 | if ((in = BIO_new_fp(stdin, BIO_NOCLOSE)) == NULL) |
880 | goto end; | ||
881 | } | ||
870 | 882 | ||
871 | if (smime_config.operation & SMIME_IP) { | 883 | if (smime_config.operation & SMIME_IP) { |
872 | if (smime_config.informat == FORMAT_SMIME) | 884 | if (smime_config.informat == FORMAT_SMIME) |
@@ -899,15 +911,18 @@ smime_main(int argc, char **argv) | |||
899 | goto end; | 911 | goto end; |
900 | } | 912 | } |
901 | } else { | 913 | } else { |
902 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 914 | if ((out = BIO_new_fp(stdout, BIO_NOCLOSE)) == NULL) |
915 | goto end; | ||
903 | } | 916 | } |
904 | 917 | ||
905 | if (smime_config.operation == SMIME_VERIFY) { | 918 | if (smime_config.operation == SMIME_VERIFY) { |
906 | if ((store = setup_verify(bio_err, smime_config.CAfile, smime_config.CApath)) == NULL) | 919 | if ((store = setup_verify(bio_err, smime_config.CAfile, smime_config.CApath)) == NULL) |
907 | goto end; | 920 | goto end; |
908 | X509_STORE_set_verify_cb(store, smime_cb); | 921 | X509_STORE_set_verify_cb(store, smime_cb); |
909 | if (smime_config.vpm != NULL) | 922 | if (smime_config.vpm != NULL) { |
910 | X509_STORE_set1_param(store, smime_config.vpm); | 923 | if (!X509_STORE_set1_param(store, smime_config.vpm)) |
924 | goto end; | ||
925 | } | ||
911 | } | 926 | } |
912 | ret = 3; | 927 | ret = 3; |
913 | 928 | ||
@@ -925,14 +940,16 @@ smime_main(int argc, char **argv) | |||
925 | if (smime_config.flags & PKCS7_DETACHED) { | 940 | if (smime_config.flags & PKCS7_DETACHED) { |
926 | if (smime_config.outformat == FORMAT_SMIME) | 941 | if (smime_config.outformat == FORMAT_SMIME) |
927 | smime_config.flags |= PKCS7_STREAM; | 942 | smime_config.flags |= PKCS7_STREAM; |
928 | } else if (smime_config.indef) | 943 | } else if (smime_config.indef) { |
929 | smime_config.flags |= PKCS7_STREAM; | 944 | smime_config.flags |= PKCS7_STREAM; |
945 | } | ||
930 | smime_config.flags |= PKCS7_PARTIAL; | 946 | smime_config.flags |= PKCS7_PARTIAL; |
931 | p7 = PKCS7_sign(NULL, NULL, other, in, smime_config.flags); | 947 | p7 = PKCS7_sign(NULL, NULL, other, in, smime_config.flags); |
932 | if (p7 == NULL) | 948 | if (p7 == NULL) |
933 | goto end; | 949 | goto end; |
934 | } else | 950 | } else { |
935 | smime_config.flags |= PKCS7_REUSE_DIGEST; | 951 | smime_config.flags |= PKCS7_REUSE_DIGEST; |
952 | } | ||
936 | for (i = 0; i < sk_OPENSSL_STRING_num(smime_config.sksigners); i++) { | 953 | for (i = 0; i < sk_OPENSSL_STRING_num(smime_config.sksigners); i++) { |
937 | smime_config.signerfile = sk_OPENSSL_STRING_value(smime_config.sksigners, i); | 954 | smime_config.signerfile = sk_OPENSSL_STRING_value(smime_config.sksigners, i); |
938 | smime_config.keyfile = sk_OPENSSL_STRING_value(smime_config.skkeys, i); | 955 | smime_config.keyfile = sk_OPENSSL_STRING_value(smime_config.skkeys, i); |
@@ -970,13 +987,14 @@ smime_main(int argc, char **argv) | |||
970 | } | 987 | } |
971 | } else if (smime_config.operation == SMIME_VERIFY) { | 988 | } else if (smime_config.operation == SMIME_VERIFY) { |
972 | STACK_OF(X509) *signers; | 989 | STACK_OF(X509) *signers; |
973 | if (PKCS7_verify(p7, other, store, indata, out, smime_config.flags)) | 990 | if (PKCS7_verify(p7, other, store, indata, out, smime_config.flags)) { |
974 | BIO_printf(bio_err, "Verification successful\n"); | 991 | BIO_printf(bio_err, "Verification successful\n"); |
975 | else { | 992 | } else { |
976 | BIO_printf(bio_err, "Verification failure\n"); | 993 | BIO_printf(bio_err, "Verification failure\n"); |
977 | goto end; | 994 | goto end; |
978 | } | 995 | } |
979 | signers = PKCS7_get0_signers(p7, other, smime_config.flags); | 996 | if ((signers = PKCS7_get0_signers(p7, other, smime_config.flags)) == NULL) |
997 | goto end; | ||
980 | if (!save_certs(smime_config.signerfile, signers)) { | 998 | if (!save_certs(smime_config.signerfile, signers)) { |
981 | BIO_printf(bio_err, "Error writing signers to %s\n", | 999 | BIO_printf(bio_err, "Error writing signers to %s\n", |
982 | smime_config.signerfile); | 1000 | smime_config.signerfile); |
@@ -984,9 +1002,9 @@ smime_main(int argc, char **argv) | |||
984 | goto end; | 1002 | goto end; |
985 | } | 1003 | } |
986 | sk_X509_free(signers); | 1004 | sk_X509_free(signers); |
987 | } else if (smime_config.operation == SMIME_PK7OUT) | 1005 | } else if (smime_config.operation == SMIME_PK7OUT) { |
988 | PEM_write_bio_PKCS7(out, p7); | 1006 | PEM_write_bio_PKCS7(out, p7); |
989 | else { | 1007 | } else { |
990 | if (smime_config.to != NULL) | 1008 | if (smime_config.to != NULL) |
991 | BIO_printf(out, "To: %s\n", smime_config.to); | 1009 | BIO_printf(out, "To: %s\n", smime_config.to); |
992 | if (smime_config.from != NULL) | 1010 | if (smime_config.from != NULL) |
@@ -994,20 +1012,27 @@ smime_main(int argc, char **argv) | |||
994 | if (smime_config.subject != NULL) | 1012 | if (smime_config.subject != NULL) |
995 | BIO_printf(out, "Subject: %s\n", smime_config.subject); | 1013 | BIO_printf(out, "Subject: %s\n", smime_config.subject); |
996 | if (smime_config.outformat == FORMAT_SMIME) { | 1014 | if (smime_config.outformat == FORMAT_SMIME) { |
997 | if (smime_config.operation == SMIME_RESIGN) | 1015 | if (smime_config.operation == SMIME_RESIGN) { |
998 | SMIME_write_PKCS7(out, p7, indata, smime_config.flags); | 1016 | if (!SMIME_write_PKCS7(out, p7, indata, smime_config.flags)) |
999 | else | 1017 | goto end; |
1000 | SMIME_write_PKCS7(out, p7, in, smime_config.flags); | 1018 | } else { |
1001 | } else if (smime_config.outformat == FORMAT_PEM) | 1019 | if (!SMIME_write_PKCS7(out, p7, in, smime_config.flags)) |
1002 | PEM_write_bio_PKCS7_stream(out, p7, in, smime_config.flags); | 1020 | goto end; |
1003 | else if (smime_config.outformat == FORMAT_ASN1) | 1021 | } |
1004 | i2d_PKCS7_bio_stream(out, p7, in, smime_config.flags); | 1022 | } else if (smime_config.outformat == FORMAT_PEM) { |
1005 | else { | 1023 | if (!PEM_write_bio_PKCS7_stream(out, p7, in, smime_config.flags)) |
1024 | goto end; | ||
1025 | } else if (smime_config.outformat == FORMAT_ASN1) { | ||
1026 | if (!i2d_PKCS7_bio_stream(out, p7, in, smime_config.flags)) | ||
1027 | goto end; | ||
1028 | } else { | ||
1006 | BIO_printf(bio_err, "Bad output format for PKCS#7 file\n"); | 1029 | BIO_printf(bio_err, "Bad output format for PKCS#7 file\n"); |
1007 | goto end; | 1030 | goto end; |
1008 | } | 1031 | } |
1009 | } | 1032 | } |
1033 | |||
1010 | ret = 0; | 1034 | ret = 0; |
1035 | |||
1011 | end: | 1036 | end: |
1012 | if (ret) | 1037 | if (ret) |
1013 | ERR_print_errors(bio_err); | 1038 | ERR_print_errors(bio_err); |