From 8c9c9a155f34da62313fce09c809cc91f3184a52 Mon Sep 17 00:00:00 2001
From: tb <>
Date: Wed, 28 Feb 2024 16:26:08 +0000
Subject: Small tweak for X509_check_purpose()

ok jsing
---
 src/lib/libcrypto/x509/x509_purp.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/lib/libcrypto/x509/x509_purp.c b/src/lib/libcrypto/x509/x509_purp.c
index 35f20e2bc3..1735e70cae 100644
--- a/src/lib/libcrypto/x509/x509_purp.c
+++ b/src/lib/libcrypto/x509/x509_purp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: x509_purp.c,v 1.35 2024/01/07 16:22:46 tb Exp $ */
+/* $OpenBSD: x509_purp.c,v 1.36 2024/02/28 16:26:08 tb Exp $ */
 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2001.
  */
@@ -177,10 +177,12 @@ X509_check_purpose(X509 *x, int id, int ca)
 
 	if (id == -1)
 		return 1;
-	idx = X509_PURPOSE_get_by_id(id);
-	if (idx == -1)
+
+	if ((idx = X509_PURPOSE_get_by_id(id)) == -1)
+		return -1;
+	if ((pt = X509_PURPOSE_get0(idx)) == NULL)
 		return -1;
-	pt = X509_PURPOSE_get0(idx);
+
 	return pt->check_purpose(pt, x, ca);
 }
 LCRYPTO_ALIAS(X509_check_purpose);
-- 
cgit v1.2.3-55-g6feb