summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/x509/x509_verify.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/libcrypto/x509/x509_verify.c b/src/lib/libcrypto/x509/x509_verify.c
index a530275ac9..fc3fbc14da 100644
--- a/src/lib/libcrypto/x509/x509_verify.c
+++ b/src/lib/libcrypto/x509/x509_verify.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_verify.c,v 1.74 2026/03/31 13:58:05 jsing Exp $ */ 1/* $OpenBSD: x509_verify.c,v 1.75 2026/04/01 14:38:26 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2020-2021 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -666,13 +666,13 @@ x509_verify_build_chains(struct x509_verify_ctx *ctx, X509 *cert,
666 return; 666 return;
667 667
668 depth = sk_X509_num(current_chain->certs); 668 depth = sk_X509_num(current_chain->certs);
669 if (depth > 0)
670 depth--;
669 if (depth >= ctx->max_depth) { 671 if (depth >= ctx->max_depth) {
670 (void)x509_verify_cert_error(ctx, cert, depth, 672 (void)x509_verify_cert_error(ctx, cert, depth,
671 X509_V_ERR_CERT_CHAIN_TOO_LONG, 0); 673 X509_V_ERR_CERT_CHAIN_TOO_LONG, 0);
672 return; 674 return;
673 } 675 }
674 if (depth > 0)
675 depth--;
676 676
677 count = ctx->chains_count; 677 count = ctx->chains_count;
678 678
@@ -978,8 +978,8 @@ x509_verify_ctx_new_from_xsc(X509_STORE_CTX *xsc)
978 (ctx->intermediates = X509_chain_up_ref(xsc->untrusted)) == NULL) 978 (ctx->intermediates = X509_chain_up_ref(xsc->untrusted)) == NULL)
979 goto err; 979 goto err;
980 980
981 max_depth = X509_VERIFY_MAX_CHAIN_CERTS; 981 max_depth = X509_VERIFY_MAX_CHAIN_CERTS - 1;
982 if (xsc->param->depth > 0 && xsc->param->depth < X509_VERIFY_MAX_CHAIN_CERTS) 982 if (xsc->param->depth > 0 && xsc->param->depth < max_depth)
983 max_depth = xsc->param->depth; 983 max_depth = xsc->param->depth;
984 if (!x509_verify_ctx_set_max_depth(ctx, max_depth)) 984 if (!x509_verify_ctx_set_max_depth(ctx, max_depth))
985 goto err; 985 goto err;
@@ -1008,7 +1008,7 @@ x509_verify_ctx_new(STACK_OF(X509) *roots)
1008 goto err; 1008 goto err;
1009 } 1009 }
1010 1010
1011 ctx->max_depth = X509_VERIFY_MAX_CHAIN_CERTS; 1011 ctx->max_depth = X509_VERIFY_MAX_CHAIN_CERTS - 1;
1012 ctx->max_chains = X509_VERIFY_MAX_CHAINS; 1012 ctx->max_chains = X509_VERIFY_MAX_CHAINS;
1013 ctx->max_sigs = X509_VERIFY_MAX_SIGCHECKS; 1013 ctx->max_sigs = X509_VERIFY_MAX_SIGCHECKS;
1014 1014
@@ -1035,7 +1035,7 @@ x509_verify_ctx_free(struct x509_verify_ctx *ctx)
1035int 1035int
1036x509_verify_ctx_set_max_depth(struct x509_verify_ctx *ctx, size_t max) 1036x509_verify_ctx_set_max_depth(struct x509_verify_ctx *ctx, size_t max)
1037{ 1037{
1038 if (max < 1 || max > X509_VERIFY_MAX_CHAIN_CERTS) 1038 if (max < 1 || max >= X509_VERIFY_MAX_CHAIN_CERTS)
1039 return 0; 1039 return 0;
1040 ctx->max_depth = max; 1040 ctx->max_depth = max;
1041 return 1; 1041 return 1;