]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a helper function to delete the extension list
authorDavid Benjamin <davidben@google.com>
Sun, 31 Aug 2025 22:09:52 +0000 (18:09 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 9 Sep 2025 09:13:40 +0000 (11:13 +0200)
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28398)

(cherry picked from commit 9e8898b6b6032a69f1002ab823a1cc0bba109b50)

crypto/x509/x509_ext.c

index bed20bd5aebd900db5b5a89dd24c1bb89de5d17b..e004a07d8880ae288e508e22b65562e9a969a79b 100644 (file)
@@ -42,19 +42,23 @@ X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc)
     return X509v3_get_ext(x->crl.extensions, loc);
 }
 
-X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
+static X509_EXTENSION *delete_ext(STACK_OF(X509_EXTENSION) **sk, int loc)
 {
-    X509_EXTENSION *ret = X509v3_delete_ext(x->crl.extensions, loc);
+    X509_EXTENSION *ret = X509v3_delete_ext(*sk, loc);
 
     /* Empty extension lists are omitted. */
-    if (x->crl.extensions != NULL &&
-        sk_X509_EXTENSION_num(x->crl.extensions) == 0) {
-        sk_X509_EXTENSION_pop_free(x->crl.extensions, X509_EXTENSION_free);
-        x->crl.extensions = NULL;
+    if (*sk != NULL && sk_X509_EXTENSION_num(*sk) == 0) {
+        sk_X509_EXTENSION_pop_free(*sk, X509_EXTENSION_free);
+        *sk = NULL;
     }
     return ret;
 }
 
+X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc)
+{
+    return delete_ext(&x->crl.extensions, loc);
+}
+
 void *X509_CRL_get_ext_d2i(const X509_CRL *x, int nid, int *crit, int *idx)
 {
     return X509V3_get_d2i(x->crl.extensions, nid, crit, idx);
@@ -99,16 +103,7 @@ X509_EXTENSION *X509_get_ext(const X509 *x, int loc)
 
 X509_EXTENSION *X509_delete_ext(X509 *x, int loc)
 {
-    X509_EXTENSION *ret = X509v3_delete_ext(x->cert_info.extensions, loc);
-
-    /* Empty extension lists are omitted. */
-    if (x->cert_info.extensions != NULL &&
-        sk_X509_EXTENSION_num(x->cert_info.extensions) == 0) {
-        sk_X509_EXTENSION_pop_free(x->cert_info.extensions,
-                                   X509_EXTENSION_free);
-        x->cert_info.extensions = NULL;
-    }
-    return ret;
+    return delete_ext(&x->cert_info.extensions, loc);
 }
 
 int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc)
@@ -156,15 +151,7 @@ X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc)
 
 X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc)
 {
-    X509_EXTENSION *ret = X509v3_delete_ext(x->extensions, loc);
-
-    /* Empty extension lists are omitted. */
-    if (x->extensions != NULL &&
-        sk_X509_EXTENSION_num(x->extensions) == 0) {
-        sk_X509_EXTENSION_pop_free(x->extensions, X509_EXTENSION_free);
-        x->extensions = NULL;
-    }
-    return ret;
+    return delete_ext(&x->extensions, loc);
 }
 
 int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc)