]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a helper function to copy custom extensions with old style arguments
authorSergey Kandaurov <pluknet@nginx.com>
Tue, 27 May 2025 19:01:40 +0000 (23:01 +0400)
committerMatt Caswell <matt@openssl.org>
Fri, 20 Jun 2025 14:56:58 +0000 (15:56 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27706)

(cherry picked from commit f7b10004dce1444a9712fc9e578e30576fcca6b6)

ssl/statem/extensions_cust.c

index b9d08da33f906b6cc002a068404ca23a566ef3e1..2a52e2b67edc2480164db9807a6b040af2f29551 100644 (file)
@@ -279,6 +279,31 @@ int custom_exts_copy_flags(custom_ext_methods *dst,
     return 1;
 }
 
+/* Copy old style API wrapper arguments */
+static void custom_ext_copy_old_cb(custom_ext_method *methdst,
+                                   const custom_ext_method *methsrc,
+                                   int *err)
+{
+    if (methsrc->add_cb != custom_ext_add_old_cb_wrap)
+        return;
+
+    if (*err) {
+        methdst->add_arg = NULL;
+        methdst->parse_arg = NULL;
+        return;
+    }
+
+    methdst->add_arg = OPENSSL_memdup(methsrc->add_arg,
+                                      sizeof(custom_ext_add_cb_wrap));
+    methdst->parse_arg = OPENSSL_memdup(methsrc->parse_arg,
+                                        sizeof(custom_ext_parse_cb_wrap));
+
+    if (methdst->add_arg == NULL || methdst->parse_arg == NULL)
+        *err = 1;
+
+    return;
+}
+
 /* Copy table of custom extensions */
 int custom_exts_copy(custom_ext_methods *dst, const custom_ext_methods *src)
 {
@@ -293,32 +318,8 @@ int custom_exts_copy(custom_ext_methods *dst, const custom_ext_methods *src)
             return 0;
         dst->meths_count = src->meths_count;
 
-        for (i = 0; i < src->meths_count; i++) {
-            custom_ext_method *methsrc = src->meths + i;
-            custom_ext_method *methdst = dst->meths + i;
-
-            if (methsrc->add_cb != custom_ext_add_old_cb_wrap)
-                continue;
-
-            /*
-             * We have found an old style API wrapper. We need to copy the
-             * arguments too.
-             */
-
-            if (err) {
-                methdst->add_arg = NULL;
-                methdst->parse_arg = NULL;
-                continue;
-            }
-
-            methdst->add_arg = OPENSSL_memdup(methsrc->add_arg,
-                                              sizeof(custom_ext_add_cb_wrap));
-            methdst->parse_arg = OPENSSL_memdup(methsrc->parse_arg,
-                                            sizeof(custom_ext_parse_cb_wrap));
-
-            if (methdst->add_arg == NULL || methdst->parse_arg == NULL)
-                err = 1;
-        }
+        for (i = 0; i < src->meths_count; i++)
+            custom_ext_copy_old_cb(&dst->meths[i], &src->meths[i], &err);
     }
 
     if (err) {