summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-05 17:46:44 +0000
committertb <>2022-01-05 17:46:44 +0000
commit7905640e6a9e4d817579925f9993d5e1ab76e08a (patch)
tree76e40c53e52b391e4f7d52b4e484a8bbafca2545
parent956cdcbd92eea3030e9f957b3955dfc08e16e4e9 (diff)
downloadopenbsd-7905640e6a9e4d817579925f9993d5e1ab76e08a.tar.gz
openbsd-7905640e6a9e4d817579925f9993d5e1ab76e08a.tar.bz2
openbsd-7905640e6a9e4d817579925f9993d5e1ab76e08a.zip
Add a helper function to turn unchecked (but sound) use of
sk_find + sk_value into something easier to follow and swallow. ok inoguchi jsing
-rw-r--r--src/lib/libcrypto/x509/x509_addr.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c
index 54cfd485cd..cd04f815fa 100644
--- a/src/lib/libcrypto/x509/x509_addr.c
+++ b/src/lib/libcrypto/x509/x509_addr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_addr.c,v 1.68 2022/01/05 17:44:30 tb Exp $ */ 1/* $OpenBSD: x509_addr.c,v 1.69 2022/01/05 17:46:44 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").
@@ -480,6 +480,19 @@ IPAddressFamily_cmp(const IPAddressFamily *const *a_,
480 return a->length - b->length; 480 return a->length - b->length;
481} 481}
482 482
483static IPAddressFamily *
484IPAddressFamily_find_in_parent(IPAddrBlocks *parent, IPAddressFamily *child_af)
485{
486 int index;
487
488 sk_IPAddressFamily_set_cmp_func(parent, IPAddressFamily_cmp);
489
490 if ((index = sk_IPAddressFamily_find(parent, child_af)) < 0)
491 return NULL;
492
493 return sk_IPAddressFamily_value(parent, index);
494}
495
483/* 496/*
484 * Extract the AFI from an IPAddressFamily. 497 * Extract the AFI from an IPAddressFamily.
485 * 498 *
@@ -1687,7 +1700,7 @@ X509v3_addr_subset(IPAddrBlocks *child, IPAddrBlocks *parent)
1687{ 1700{
1688 IPAddressFamily *fc, *fp; 1701 IPAddressFamily *fc, *fp;
1689 IPAddressOrRanges *aorc, *aorp; 1702 IPAddressOrRanges *aorc, *aorp;
1690 int i, j, length; 1703 int i, length;
1691 1704
1692 if (child == NULL || child == parent) 1705 if (child == NULL || child == parent)
1693 return 1; 1706 return 1;
@@ -1697,14 +1710,10 @@ X509v3_addr_subset(IPAddrBlocks *child, IPAddrBlocks *parent)
1697 if (X509v3_addr_inherits(child) || X509v3_addr_inherits(parent)) 1710 if (X509v3_addr_inherits(child) || X509v3_addr_inherits(parent))
1698 return 0; 1711 return 0;
1699 1712
1700 sk_IPAddressFamily_set_cmp_func(parent, IPAddressFamily_cmp);
1701
1702 for (i = 0; i < sk_IPAddressFamily_num(child); i++) { 1713 for (i = 0; i < sk_IPAddressFamily_num(child); i++) {
1703 fc = sk_IPAddressFamily_value(child, i); 1714 fc = sk_IPAddressFamily_value(child, i);
1704 1715
1705 j = sk_IPAddressFamily_find(parent, fc); 1716 if ((fp = IPAddressFamily_find_in_parent(parent, fc)) == NULL)
1706 fp = sk_IPAddressFamily_value(parent, j);
1707 if (fp == NULL)
1708 return 0; 1717 return 0;
1709 1718
1710 if (!IPAddressFamily_afi_length(fp, &length)) 1719 if (!IPAddressFamily_afi_length(fp, &length))
@@ -1749,7 +1758,7 @@ addr_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509) *chain,
1749 IPAddressOrRanges *aorc, *aorp; 1758 IPAddressOrRanges *aorc, *aorp;
1750 X509 *cert = NULL; 1759 X509 *cert = NULL;
1751 int depth = -1; 1760 int depth = -1;
1752 int i, k; 1761 int i;
1753 unsigned int length; 1762 unsigned int length;
1754 int ret = 1; 1763 int ret = 1;
1755 1764
@@ -1818,8 +1827,6 @@ addr_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509) *chain,
1818 goto done; 1827 goto done;
1819 } 1828 }
1820 1829
1821 sk_IPAddressFamily_set_cmp_func(parent, IPAddressFamily_cmp);
1822
1823 /* 1830 /*
1824 * Check that the child's resources are covered by the parent. 1831 * Check that the child's resources are covered by the parent.
1825 * Each covered resource is replaced with the parent's resource 1832 * Each covered resource is replaced with the parent's resource
@@ -1829,9 +1836,7 @@ addr_validate_path_internal(X509_STORE_CTX *ctx, STACK_OF(X509) *chain,
1829 for (i = 0; i < sk_IPAddressFamily_num(child); i++) { 1836 for (i = 0; i < sk_IPAddressFamily_num(child); i++) {
1830 fc = sk_IPAddressFamily_value(child, i); 1837 fc = sk_IPAddressFamily_value(child, i);
1831 1838
1832 k = sk_IPAddressFamily_find(parent, fc); 1839 fp = IPAddressFamily_find_in_parent(parent, fc);
1833 fp = sk_IPAddressFamily_value(parent, k);
1834
1835 if (fp == NULL) { 1840 if (fp == NULL) {
1836 /* 1841 /*
1837 * If we have no match in the parent and the 1842 * If we have no match in the parent and the