]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:kdc: Avoid copying data if not needed
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Thu, 16 Mar 2023 20:16:17 +0000 (09:16 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 20 Mar 2023 00:22:32 +0000 (00:22 +0000)
krb5_pac_add_buffer() makes its own copy of the data we pass in. We
don't need to make yet another copy.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/kdc/pac-glue.c

index 704cfcda66133d3874fd4454e88829d2d1c3dd2c..6e3dc196227e5e9f9bc37ff09099b9f8ba828c66 100644 (file)
@@ -2042,12 +2042,9 @@ krb5_error_code samba_kdc_update_pac(TALLOC_CTX *mem_ctx,
                }
 
                if (type_blob.length != 0) {
-                       code = smb_krb5_copy_data_contents(&type_data,
-                                                          type_blob.data,
-                                                          type_blob.length);
-                       if (code != 0) {
-                               goto done;
-                       }
+                       type_data = smb_krb5_data_from_blob(type_blob);
+                       code = krb5_pac_add_buffer(context, new_pac,
+                                                  type, &type_data);
                } else {
                        code = krb5_pac_get_buffer(context,
                                                   old_pac,
@@ -2056,17 +2053,17 @@ krb5_error_code samba_kdc_update_pac(TALLOC_CTX *mem_ctx,
                        if (code != 0) {
                                goto done;
                        }
+                       /*
+                        * Passing a NULL pointer into krb5_pac_add_buffer() is
+                        * not allowed, so pass null_data instead if needed.
+                        */
+                       code = krb5_pac_add_buffer(context,
+                                                  new_pac,
+                                                  type,
+                                                  (type_data.data != NULL) ? &type_data : &null_data);
+                       smb_krb5_free_data_contents(context, &type_data);
                }
 
-               /*
-                * Passing a NULL pointer into krb5_pac_add_buffer() is
-                * not allowed, so pass null_data instead if needed.
-                */
-               code = krb5_pac_add_buffer(context,
-                                          new_pac,
-                                          type,
-                                          (type_data.data != NULL) ? &type_data : &null_data);
-               smb_krb5_free_data_contents(context, &type_data);
                if (code != 0) {
                        goto done;
                }