]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use mempcpy
authorJan Janssen <medhefgo@web.de>
Tue, 6 Sep 2022 08:14:25 +0000 (10:14 +0200)
committerJan Janssen <medhefgo@web.de>
Wed, 7 Sep 2022 10:51:16 +0000 (12:51 +0200)
src/boot/efi/boot.c
src/boot/efi/cpio.c
src/boot/efi/stub.c
src/boot/efi/util.c

index 9c1d95e67256d43f1dcfb8e536dd54e32863e993..a4804887acc658641f0b25ea5fe851c3c467ff18 100644 (file)
@@ -2416,14 +2416,8 @@ static void config_write_entries_to_variable(Config *config) {
 
         p = buffer = xmalloc(sz);
 
-        for (UINTN i = 0; i < config->entry_count; i++) {
-                UINTN l;
-
-                l = strsize16(config->entries[i]->id);
-                memcpy(p, config->entries[i]->id, l);
-
-                p += l;
-        }
+        for (UINTN i = 0; i < config->entry_count; i++)
+                p = mempcpy(p, config->entries[i]->id, strsize16(config->entries[i]->id));
 
         assert(p == buffer + sz);
 
index 9ffa935e0f63cbbaab22536505e009cd88e04c6b..b21cf53b4659fa89a0ce8e8c0f752fbaa5d26cbc 100644 (file)
@@ -116,8 +116,7 @@ static EFI_STATUS pack_cpio_one(
         *cpio_buffer = a;
         a = (char *) *cpio_buffer + *cpio_buffer_size;
 
-        memcpy(a, "070701", 6); /* magic ID */
-        a += 6;
+        a = mempcpy(a, "070701", 6); /* magic ID */
 
         a = write_cpio_word(a, (*inode_counter)++);                         /* inode */
         a = write_cpio_word(a, access_mode | 0100000 /* = S_IFREG */);      /* mode */
@@ -139,16 +138,14 @@ static EFI_STATUS pack_cpio_one(
         a = write_cpio_word(a, target_dir_prefix_size + fname_size + 2);    /* fname size */
         a = write_cpio_word(a, 0);                                          /* "crc" */
 
-        memcpy(a, target_dir_prefix, target_dir_prefix_size);
-        a += target_dir_prefix_size;
+        a = mempcpy(a, target_dir_prefix, target_dir_prefix_size);
         *(a++) = '/';
         a = mangle_filename(a, fname);
 
         /* Pad to next multiple of 4 */
         a = pad4(a, *cpio_buffer);
 
-        memcpy(a, contents, contents_size);
-        a += contents_size;
+        a = mempcpy(a, contents, contents_size);
 
         /* Pad to next multiple of 4 */
         a = pad4(a, *cpio_buffer);
@@ -198,8 +195,7 @@ static EFI_STATUS pack_cpio_dir(
         *cpio_buffer = a = xrealloc(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
         a = (char *) *cpio_buffer + *cpio_buffer_size;
 
-        memcpy(a, "070701", 6); /* magic ID */
-        a += 6;
+        a = mempcpy(a, "070701", 6); /* magic ID */
 
         a = write_cpio_word(a, (*inode_counter)++);                         /* inode */
         a = write_cpio_word(a, access_mode | 0040000 /* = S_IFDIR */);      /* mode */
@@ -215,8 +211,7 @@ static EFI_STATUS pack_cpio_dir(
         a = write_cpio_word(a, path_size + 1);                              /* fname size */
         a = write_cpio_word(a, 0);                                          /* "crc" */
 
-        memcpy(a, path, path_size + 1);
-        a += path_size + 1;
+        a = mempcpy(a, path, path_size + 1);
 
         /* Pad to next multiple of 4 */
         a = pad4(a, *cpio_buffer);
index 003ae8c99a0bc192bac180a50282093e4f98d7b0..3f6832e0c2d082cbde186f51139cba786def47e8 100644 (file)
@@ -69,8 +69,7 @@ static EFI_STATUS combine_initrd(
 
                 /* Order matters, the real initrd must come first, since it might include microcode updates
                  * which the kernel only looks for in the first cpio archive */
-                memcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
-                p += initrd_size;
+                p = mempcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
 
                 pad = ALIGN4(initrd_size) - initrd_size;
                 if (pad > 0)  {
@@ -79,20 +78,12 @@ static EFI_STATUS combine_initrd(
                 }
         }
 
-        if (credential_initrd) {
-                memcpy(p, credential_initrd, credential_initrd_size);
-                p += credential_initrd_size;
-        }
-
-        if (global_credential_initrd) {
-                memcpy(p, global_credential_initrd, global_credential_initrd_size);
-                p += global_credential_initrd_size;
-        }
-
-        if (sysext_initrd) {
-                memcpy(p, sysext_initrd, sysext_initrd_size);
-                p += sysext_initrd_size;
-        }
+        if (credential_initrd)
+                p = mempcpy(p, credential_initrd, credential_initrd_size);
+        if (global_credential_initrd)
+                p = mempcpy(p, global_credential_initrd, global_credential_initrd_size);
+        if (sysext_initrd)
+                p = mempcpy(p, sysext_initrd, sysext_initrd_size);
 
         assert((uint8_t*) PHYSICAL_ADDRESS_TO_POINTER(base) + n == p);
 
index a41dbaa43e1f6278c3d082875f75cf85b7c33592..ce1f981817f448b7b1a983f32a27e8518eaa5962 100644 (file)
@@ -751,14 +751,11 @@ EFI_STATUS make_file_device_path(EFI_HANDLE device, const char16_t *file, EFI_DE
                 end_node = NextDevicePathNode(end_node);
 
         size_t file_size = strsize16(file);
-        size_t dp_size = ((uint8_t *) end_node - (uint8_t *) dp) + END_DEVICE_PATH_LENGTH;
+        size_t dp_size = (uint8_t *) end_node - (uint8_t *) dp;
 
         /* Make a copy that can also hold a file media device path. */
-        *ret_dp = xmalloc(dp_size + file_size + SIZE_OF_FILEPATH_DEVICE_PATH);
-        memcpy(*ret_dp, dp, dp_size);
-
-        /* Point dp to the end node of the copied device path. */
-        dp = (EFI_DEVICE_PATH *) ((uint8_t *) *ret_dp + dp_size - END_DEVICE_PATH_LENGTH);
+        *ret_dp = xmalloc(dp_size + file_size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
+        dp = mempcpy(*ret_dp, dp, dp_size);
 
         /* Replace end node with file media device path. */
         FILEPATH_DEVICE_PATH *file_dp = (FILEPATH_DEVICE_PATH *) dp;