summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2022-01-05 07:47:15 +0000
committertb <>2022-01-05 07:47:15 +0000
commit6a84e3bf371065aba96d0c301e5f83493d7eae97 (patch)
tree584bfee87260953fa4a57fcfebc354746211259d /src/lib
parent1e2931f5b7e846111974b4afe7f6d0d5b2a761f3 (diff)
downloadopenbsd-6a84e3bf371065aba96d0c301e5f83493d7eae97.tar.gz
openbsd-6a84e3bf371065aba96d0c301e5f83493d7eae97.tar.bz2
openbsd-6a84e3bf371065aba96d0c301e5f83493d7eae97.zip
Remove a bogus memcmp in range_should_be_prefix()
range_should_be_prefix() currently always fails. The reason for this is that OpenSSL commit 42d7d7dd incorrectly moved a memcmp() out of an assertion. As a consequence, the library emits and accepts incorrectly encoded ipAddrBlock extensions since it will never detect ranges that MUST be encoded as a prefix according to RFC 3779, 2.2.3.7. The return -1 from this memcmp() indicates to the callers that the range should be expressed as a range, so callers must check beforehand that min <= max to be able to fail. Thus, remove this memcmp() and add a check to make_addressRange(), the only caller that didn't already ensure that min <= max. This fixes the noisy output in regress/lib/libcrypto/x509/rfc3779. ok inoguchi jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/x509/x509_addr.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c
index 705fc7df32..c6eac91aaa 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.61 2022/01/05 07:37:01 tb Exp $ */ 1/* $OpenBSD: x509_addr.c,v 1.62 2022/01/05 07:47:15 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").
@@ -755,6 +755,8 @@ v6IPAddressOrRange_cmp(const IPAddressOrRange *const *a,
755/* 755/*
756 * Calculate whether a range collapses to a prefix. 756 * Calculate whether a range collapses to a prefix.
757 * See last paragraph of RFC 3779 2.2.3.7. 757 * See last paragraph of RFC 3779 2.2.3.7.
758 *
759 * It's the caller's responsibility to ensure that min <= max.
758 */ 760 */
759static int 761static int
760range_should_be_prefix(const unsigned char *min, const unsigned char *max, 762range_should_be_prefix(const unsigned char *min, const unsigned char *max,
@@ -763,8 +765,6 @@ range_should_be_prefix(const unsigned char *min, const unsigned char *max,
763 unsigned char mask; 765 unsigned char mask;
764 int i, j; 766 int i, j;
765 767
766 if (memcmp(min, max, length) <= 0)
767 return -1;
768 for (i = 0; i < length && min[i] == max[i]; i++) 768 for (i = 0; i < length && min[i] == max[i]; i++)
769 continue; 769 continue;
770 for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xff; j--) 770 for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xff; j--)
@@ -863,6 +863,9 @@ make_addressRange(IPAddressOrRange **result, unsigned char *min,
863 IPAddressOrRange *aor; 863 IPAddressOrRange *aor;
864 int i, prefix_len; 864 int i, prefix_len;
865 865
866 if (memcmp(min, max, length) > 0)
867 return 0;
868
866 if ((prefix_len = range_should_be_prefix(min, max, length)) >= 0) 869 if ((prefix_len = range_should_be_prefix(min, max, length)) >= 0)
867 return make_addressPrefix(result, min, afi, prefix_len); 870 return make_addressPrefix(result, min, afi, prefix_len);
868 871