diff options
author | tb <> | 2021-12-24 02:28:52 +0000 |
---|---|---|
committer | tb <> | 2021-12-24 02:28:52 +0000 |
commit | cff474799d36b37cdb84fdff7387665a63df7c03 (patch) | |
tree | 778069e79be000145d87406253a74eeacad7e404 /src | |
parent | 590db753358a3347436824299d28c2b7b7f2df2b (diff) | |
download | openbsd-cff474799d36b37cdb84fdff7387665a63df7c03.tar.gz openbsd-cff474799d36b37cdb84fdff7387665a63df7c03.tar.bz2 openbsd-cff474799d36b37cdb84fdff7387665a63df7c03.zip |
Remove asserts from asid_validate_path_internal()
The first asserts ensure that things checked in the callers hold true.
Turn them into error checks and set the error on the X509_STORE_CTX
if it's present. Checking sk_value(..., i) with i < sk_num(...) isn't
useful, particularly if that check is done via an assert. Turn one
remaining assert into a NULL check. Finally, simplify the sk_num()
checks in the callers.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/x509_asid.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/lib/libcrypto/x509/x509_asid.c b/src/lib/libcrypto/x509/x509_asid.c index bf51c9bb2a..78141b3fb9 100644 --- a/src/lib/libcrypto/x509/x509_asid.c +++ b/src/lib/libcrypto/x509/x509_asid.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_asid.c,v 1.26 2021/12/24 02:23:44 tb Exp $ */ | 1 | /* $OpenBSD: x509_asid.c,v 1.27 2021/12/24 02:28:52 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Contributed to the OpenSSL Project by the American Registry for | 3 | * Contributed to the OpenSSL Project by the American Registry for |
4 | * Internet Numbers ("ARIN"). | 4 | * Internet Numbers ("ARIN"). |
@@ -979,16 +979,22 @@ X509v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b) | |||
979 | * Core code for RFC 3779 3.3 path validation. | 979 | * Core code for RFC 3779 3.3 path validation. |
980 | */ | 980 | */ |
981 | static int | 981 | static int |
982 | asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509)*chain, | 982 | asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509) *chain, |
983 | ASIdentifiers *ext) | 983 | ASIdentifiers *ext) |
984 | { | 984 | { |
985 | ASIdOrRanges *child_as = NULL, *child_rdi = NULL; | 985 | ASIdOrRanges *child_as = NULL, *child_rdi = NULL; |
986 | int i, ret = 1, inherit_as = 0, inherit_rdi = 0; | 986 | int i, ret = 1, inherit_as = 0, inherit_rdi = 0; |
987 | X509 *x; | 987 | X509 *x; |
988 | 988 | ||
989 | OPENSSL_assert(chain != NULL && sk_X509_num(chain) > 0); | 989 | /* We need a non-empty chain to test against. */ |
990 | OPENSSL_assert(ctx != NULL || ext != NULL); | 990 | if (sk_X509_num(chain) <= 0) |
991 | OPENSSL_assert(ctx == NULL || ctx->verify_cb != NULL); | 991 | goto err; |
992 | /* We need either a store ctx or an extension to work with. */ | ||
993 | if (ctx == NULL && ext == NULL) | ||
994 | goto err; | ||
995 | /* If there is a store ctx, it needs a verify_cb. */ | ||
996 | if (ctx != NULL && ctx->verify_cb == NULL) | ||
997 | goto err; | ||
992 | 998 | ||
993 | /* | 999 | /* |
994 | * Figure out where to start. If we don't have an extension to | 1000 | * Figure out where to start. If we don't have an extension to |
@@ -1033,7 +1039,6 @@ asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509)*chain, | |||
1033 | */ | 1039 | */ |
1034 | for (i++; i < sk_X509_num(chain); i++) { | 1040 | for (i++; i < sk_X509_num(chain); i++) { |
1035 | x = sk_X509_value(chain, i); | 1041 | x = sk_X509_value(chain, i); |
1036 | OPENSSL_assert(x != NULL); | ||
1037 | 1042 | ||
1038 | if (x->rfc3779_asid == NULL) { | 1043 | if (x->rfc3779_asid == NULL) { |
1039 | if (child_as != NULL || child_rdi != NULL) | 1044 | if (child_as != NULL || child_rdi != NULL) |
@@ -1080,7 +1085,9 @@ asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509)*chain, | |||
1080 | /* | 1085 | /* |
1081 | * Trust anchor can't inherit. | 1086 | * Trust anchor can't inherit. |
1082 | */ | 1087 | */ |
1083 | OPENSSL_assert(x != NULL); | 1088 | |
1089 | if (x == NULL) | ||
1090 | goto err; | ||
1084 | 1091 | ||
1085 | if (x->rfc3779_asid != NULL) { | 1092 | if (x->rfc3779_asid != NULL) { |
1086 | if (x->rfc3779_asid->asnum != NULL && | 1093 | if (x->rfc3779_asid->asnum != NULL && |
@@ -1093,6 +1100,12 @@ asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509)*chain, | |||
1093 | 1100 | ||
1094 | done: | 1101 | done: |
1095 | return ret; | 1102 | return ret; |
1103 | |||
1104 | err: | ||
1105 | if (ctx != NULL) | ||
1106 | ctx->error = X509_V_ERR_UNSPECIFIED; | ||
1107 | |||
1108 | return 0; | ||
1096 | } | 1109 | } |
1097 | 1110 | ||
1098 | #undef validation_err | 1111 | #undef validation_err |
@@ -1103,9 +1116,7 @@ asid_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509)*chain, | |||
1103 | int | 1116 | int |
1104 | X509v3_asid_validate_path(X509_STORE_CTX *ctx) | 1117 | X509v3_asid_validate_path(X509_STORE_CTX *ctx) |
1105 | { | 1118 | { |
1106 | if (ctx->chain == NULL || | 1119 | if (sk_X509_num(ctx->chain) <= 0 || ctx->verify_cb == NULL) { |
1107 | sk_X509_num(ctx->chain) == 0 || | ||
1108 | ctx->verify_cb == NULL) { | ||
1109 | ctx->error = X509_V_ERR_UNSPECIFIED; | 1120 | ctx->error = X509_V_ERR_UNSPECIFIED; |
1110 | return 0; | 1121 | return 0; |
1111 | } | 1122 | } |
@@ -1122,7 +1133,7 @@ X509v3_asid_validate_resource_set(STACK_OF(X509)*chain, ASIdentifiers *ext, | |||
1122 | { | 1133 | { |
1123 | if (ext == NULL) | 1134 | if (ext == NULL) |
1124 | return 1; | 1135 | return 1; |
1125 | if (chain == NULL || sk_X509_num(chain) == 0) | 1136 | if (sk_X509_num(chain) <= 0) |
1126 | return 0; | 1137 | return 0; |
1127 | if (!allow_inheritance && X509v3_asid_inherits(ext)) | 1138 | if (!allow_inheritance && X509v3_asid_inherits(ext)) |
1128 | return 0; | 1139 | return 0; |