diff options
author | tb <> | 2021-12-28 20:07:17 +0000 |
---|---|---|
committer | tb <> | 2021-12-28 20:07:17 +0000 |
commit | b2312e075fb4443cba28692fd6c6331e7ef2a749 (patch) | |
tree | f3acc285123c98d1d64016a9d25ac0165414ec80 /src | |
parent | 5567885d9cda37267ff204c1ffd31f41dd0425d4 (diff) | |
download | openbsd-b2312e075fb4443cba28692fd6c6331e7ef2a749.tar.gz openbsd-b2312e075fb4443cba28692fd6c6331e7ef2a749.tar.bz2 openbsd-b2312e075fb4443cba28692fd6c6331e7ef2a749.zip |
Make IPAddressFamily_cmp() more pleasing on the eye
Define and use MINIMUM() instead of a ternary operator and separate
the code from the declarations. Also, we can spare a line to make the
return legible instead of squeezing it into another ternary operator.
addressFamily->data contains a two-bytes AFI and an optional one-byte
SAFI. This function currently also compares any trailing garbage that
may be present. Since comparison functions can't really error, this
needs to be checked bofore it is used. Such checks will be added in
subsequent commits.
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/x509/x509_addr.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lib/libcrypto/x509/x509_addr.c b/src/lib/libcrypto/x509/x509_addr.c index f0ef5b8311..5f31d7307f 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.40 2021/12/28 19:59:33 tb Exp $ */ | 1 | /* $OpenBSD: x509_addr.c,v 1.41 2021/12/28 20:07:17 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"). |
@@ -1041,6 +1041,8 @@ X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, | |||
1041 | return afi_length; | 1041 | return afi_length; |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) | ||
1045 | |||
1044 | /* | 1046 | /* |
1045 | * Sort comparison function for a sequence of IPAddressFamily. | 1047 | * Sort comparison function for a sequence of IPAddressFamily. |
1046 | * | 1048 | * |
@@ -1057,9 +1059,14 @@ IPAddressFamily_cmp(const IPAddressFamily *const *a_, | |||
1057 | { | 1059 | { |
1058 | const ASN1_OCTET_STRING *a = (*a_)->addressFamily; | 1060 | const ASN1_OCTET_STRING *a = (*a_)->addressFamily; |
1059 | const ASN1_OCTET_STRING *b = (*b_)->addressFamily; | 1061 | const ASN1_OCTET_STRING *b = (*b_)->addressFamily; |
1060 | int len = ((a->length <= b->length) ? a->length : b->length); | 1062 | int len, cmp; |
1061 | int cmp = memcmp(a->data, b->data, len); | 1063 | |
1062 | return cmp ? cmp : a->length - b->length; | 1064 | len = MINIMUM(a->length, b->length); |
1065 | |||
1066 | if ((cmp = memcmp(a->data, b->data, len)) != 0) | ||
1067 | return cmp; | ||
1068 | |||
1069 | return a->length - b->length; | ||
1063 | } | 1070 | } |
1064 | 1071 | ||
1065 | /* | 1072 | /* |