From 3e1246eecfad0f9853c81a09d2b6624e8fd3f331 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 12 Jul 2024 08:44:16 +0000 Subject: [PATCH] Align X509v3_get_ext_by_critical() with X509v3_get_ext_by_OBJ() Plus, replace a manual check with a call to X509_EXTENSION_get_critical(). ok jsing --- lib/libcrypto/x509/x509_v3.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/libcrypto/x509/x509_v3.c b/lib/libcrypto/x509/x509_v3.c index 22fa7e1162e..5e8257ff834 100644 --- a/lib/libcrypto/x509/x509_v3.c +++ b/lib/libcrypto/x509/x509_v3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_v3.c,v 1.31 2024/07/12 08:39:54 tb Exp $ */ +/* $OpenBSD: x509_v3.c,v 1.32 2024/07/12 08:44:16 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -112,21 +112,18 @@ int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, int lastpos) { - int n; - X509_EXTENSION *ext; + crit = (crit != 0); - if (sk == NULL) - return -1; - lastpos++; - if (lastpos < 0) + if (++lastpos < 0) lastpos = 0; - n = sk_X509_EXTENSION_num(sk); - for (; lastpos < n; lastpos++) { - ext = sk_X509_EXTENSION_value(sk, lastpos); - if ((ext->critical > 0 && crit) || - (ext->critical <= 0 && !crit)) + + for (; lastpos < X509v3_get_ext_count(sk); lastpos++) { + const X509_EXTENSION *ext = X509v3_get_ext(sk, lastpos); + + if (X509_EXTENSION_get_critical(ext) == crit) return lastpos; } + return -1; } LCRYPTO_ALIAS(X509v3_get_ext_by_critical); -- 2.20.1