From 37f392f908b3ed4988a0bcf3ee62596398d4ef6c Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 4 Jan 2022 20:21:04 +0000 Subject: [PATCH] Make X509v3_addr_get_range() readable. Instead of checking everything in a single if statement, group the checks according to their purposes. ok inoguchi jsing --- lib/libcrypto/x509/x509_addr.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/libcrypto/x509/x509_addr.c b/lib/libcrypto/x509/x509_addr.c index fdb2f64fd26..f6dbb3a9c19 100644 --- a/lib/libcrypto/x509/x509_addr.c +++ b/lib/libcrypto/x509/x509_addr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_addr.c,v 1.52 2022/01/04 20:17:07 tb Exp $ */ +/* $OpenBSD: x509_addr.c,v 1.53 2022/01/04 20:21:04 tb Exp $ */ /* * Contributed to the OpenSSL Project by the American Registry for * Internet Numbers ("ARIN"). @@ -1088,12 +1088,22 @@ int X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, unsigned char *min, unsigned char *max, const int length) { - int afi_length = length_from_afi(afi); - if (aor == NULL || min == NULL || max == NULL || - afi_length == 0 || length < afi_length || - (aor->type != IPAddressOrRange_addressPrefix && - aor->type != IPAddressOrRange_addressRange) || - !extract_min_max(aor, min, max, afi_length)) + int afi_length; + + if (aor == NULL || min == NULL || max == NULL) + return 0; + + if ((afi_length = length_from_afi(afi)) == 0) + return 0; + + if (length < afi_length) + return 0; + + if (aor->type != IPAddressOrRange_addressPrefix && + aor->type != IPAddressOrRange_addressRange) + return 0; + + if (!extract_min_max(aor, min, max, afi_length)) return 0; return afi_length; -- 2.20.1