]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Use memcmp/memcpy/memset
authorJan Janssen <medhefgo@web.de>
Tue, 24 May 2022 11:39:00 +0000 (13:39 +0200)
committerJan Janssen <medhefgo@web.de>
Tue, 31 May 2022 13:15:01 +0000 (15:15 +0200)
15 files changed:
src/boot/efi/boot.c
src/boot/efi/cpio.c
src/boot/efi/devicetree.c
src/boot/efi/initrd.c
src/boot/efi/linux.c
src/boot/efi/linux_x86.c
src/boot/efi/measure.c
src/boot/efi/pe.c
src/boot/efi/random-seed.c
src/boot/efi/stub.c
src/boot/efi/util.c
src/boot/efi/xbootldr.c
src/fundamental/macro-fundamental.h
src/fundamental/sha256.c
src/fundamental/string-util-fundamental.h

index b75e4261a48864a9fcda3c6bf23df65ea5bd049d..e3964033c27769536e0785de07c105a541c6ffb4 100644 (file)
@@ -162,7 +162,7 @@ static BOOLEAN line_edit(
                 UINTN cursor_color = TEXT_ATTR_SWAP(COLOR_EDIT);
 
                 j = MIN(len - first, x_max);
-                CopyMem(print, line + first, j * sizeof(CHAR16));
+                memcpy(print, line + first, j * sizeof(CHAR16));
                 while (clear > 0 && j < x_max) {
                         clear--;
                         print[j++] = ' ';
@@ -1866,7 +1866,7 @@ static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const CHAR16 *loader_path) {
         if (EFI_ERROR(err) || size != read)
                 return FALSE;
 
-        return CompareMem(content, magic, sizeof(magic)) == 0;
+        return memcmp(content, magic, sizeof(magic)) == 0;
 }
 
 static ConfigEntry *config_entry_add_loader_auto(
@@ -1986,7 +1986,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
                 if (EFI_ERROR(err))
                         continue;
 
-                if (CompareMem(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
+                if (memcmp(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
                         found = TRUE;
                         break;
                 }
@@ -2434,7 +2434,7 @@ static void config_write_entries_to_variable(Config *config) {
                 UINTN l;
 
                 l = strsize16(config->entries[i]->id);
-                CopyMem(p, config->entries[i]->id, l);
+                memcpy(p, config->entries[i]->id, l);
 
                 p += l;
         }
index 5f8489635fa2f7aaf06426bca05664243bdcfd2f..8345f957f7e60df1458d95f7fb323d9cc6ba5d36 100644 (file)
@@ -116,7 +116,7 @@ static EFI_STATUS pack_cpio_one(
         *cpio_buffer = a;
         a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
 
-        CopyMem(a, "070701", 6); /* magic ID */
+        memcpy(a, "070701", 6); /* magic ID */
         a += 6;
 
         a = write_cpio_word(a, (*inode_counter)++);                         /* inode */
@@ -139,7 +139,7 @@ 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" */
 
-        CopyMem(a, target_dir_prefix, target_dir_prefix_size);
+        memcpy(a, target_dir_prefix, target_dir_prefix_size);
         a += target_dir_prefix_size;
         *(a++) = '/';
         a = mangle_filename(a, fname);
@@ -147,7 +147,7 @@ static EFI_STATUS pack_cpio_one(
         /* Pad to next multiple of 4 */
         a = pad4(a, *cpio_buffer);
 
-        CopyMem(a, contents, contents_size);
+        memcpy(a, contents, contents_size);
         a += contents_size;
 
         /* Pad to next multiple of 4 */
@@ -198,7 +198,7 @@ static EFI_STATUS pack_cpio_dir(
         *cpio_buffer = a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
         a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
 
-        CopyMem(a, "070701", 6); /* magic ID */
+        memcpy(a, "070701", 6); /* magic ID */
         a += 6;
 
         a = write_cpio_word(a, (*inode_counter)++);                         /* inode */
@@ -215,7 +215,7 @@ static EFI_STATUS pack_cpio_dir(
         a = write_cpio_word(a, path_size + 1);                              /* fname size */
         a = write_cpio_word(a, 0);                                          /* "crc" */
 
-        CopyMem(a, path, path_size + 1);
+        memcpy(a, path, path_size + 1);
         a += path_size + 1;
 
         /* Pad to next multiple of 4 */
@@ -298,7 +298,7 @@ static EFI_STATUS pack_cpio_trailer(
         assert_cc(sizeof(trailer) % 4 == 0);
 
         *cpio_buffer = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
-        CopyMem((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
+        memcpy((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
         *cpio_buffer_size += sizeof(trailer);
 
         return EFI_SUCCESS;
index b8ba52a52357a810ab013ada8bb0f0aaea697374..81c6e60ca66818eac61d41a87fb47eba03e62ae7 100644 (file)
@@ -51,7 +51,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
                 if (EFI_ERROR(err))
                         return err;
 
-                CopyMem(PHYSICAL_ADDRESS_TO_POINTER(state->addr), oldptr, len);
+                memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), oldptr, len);
                 err = BS->FreePages(oldaddr, oldpages);
                 if (EFI_ERROR(err))
                         return err;
@@ -122,7 +122,7 @@ EFI_STATUS devicetree_install_from_memory(struct devicetree_state *state,
         if (EFI_ERROR(err))
                 return err;
 
-        CopyMem(PHYSICAL_ADDRESS_TO_POINTER(state->addr), dtb_buffer, dtb_length);
+        memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), dtb_buffer, dtb_length);
 
         err = devicetree_fixup(state, dtb_length);
         if (EFI_ERROR(err))
index 3136d3b8fa35fe138e6ff121cab260b8ffe98fba..2d0984990bf8abc686bb20a91f8434335df59a6a 100644 (file)
@@ -61,7 +61,7 @@ EFIAPI EFI_STATUS initrd_load_file(
                 return EFI_BUFFER_TOO_SMALL;
         }
 
-        CopyMem(buffer, loader->address, loader->length);
+        memcpy(buffer, loader->address, loader->length);
         *buffer_size = loader->length;
         return EFI_SUCCESS;
 }
index 31413ed3a494322459622864602e4ad4b914983c..dcffea15c0cdcc1af648db4837907eb87b2952e0 100644 (file)
@@ -145,9 +145,9 @@ EFI_STATUS linux_exec(
         if (EFI_ERROR(err))
                 return EFI_OUT_OF_RESOURCES;
         new_buffer = PHYSICAL_ADDRESS_TO_POINTER(ALIGN_TO(kernel.addr, kernel_alignment));
-        CopyMem(new_buffer, linux_buffer, linux_length);
+        memcpy(new_buffer, linux_buffer, linux_length);
         /* zero out rest of memory (probably not needed, but BSS section should be 0) */
-        SetMem((UINT8 *)new_buffer + linux_length, kernel_size_of_image - linux_length, 0);
+        memset((UINT8 *)new_buffer + linux_length, 0, kernel_size_of_image - linux_length);
 
         /* get the entry point inside the relocated kernel */
         kernel_entry = (EFI_IMAGE_ENTRY_POINT) ((const UINT8 *)new_buffer + kernel_entry_address);
index 15052bdff65ccffabb261fac014ea78e305c1b45..a6c1f06939561b58b1cc91d4e2e822d6bb98694e 100644 (file)
@@ -159,7 +159,7 @@ EFI_STATUS linux_exec(
                 return err;
 
         boot_params = (struct boot_params *) PHYSICAL_ADDRESS_TO_POINTER(addr);
-        ZeroMem(boot_params, 0x4000);
+        memset(boot_params, 0, 0x4000);
         boot_params->hdr = image_params->hdr;
         boot_params->hdr.type_of_loader = 0xff;
         setup_sectors = image_params->hdr.setup_sects > 0 ? image_params->hdr.setup_sects : 4;
@@ -176,7 +176,7 @@ EFI_STATUS linux_exec(
                 if (EFI_ERROR(err))
                         return err;
 
-                CopyMem(PHYSICAL_ADDRESS_TO_POINTER(addr), cmdline, cmdline_len);
+                memcpy(PHYSICAL_ADDRESS_TO_POINTER(addr), cmdline, cmdline_len);
                 ((CHAR8 *) PHYSICAL_ADDRESS_TO_POINTER(addr))[cmdline_len] = 0;
                 boot_params->hdr.cmd_line_ptr = (UINT32) addr;
         }
index 7579b756c5c01f56c51529ae395711f536a66079..c9ce8f19e0fbf0f7d03714bcb368e6201d399f7b 100644 (file)
@@ -32,7 +32,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(
                 .PCRIndex = pcrindex,
                 .EventType = EV_IPL,
         };
-        CopyMem(tcg_event->Event, description, desc_len);
+        memcpy(tcg_event->Event, description, desc_len);
 
         return tcg->HashLogExtendEvent(
                         (EFI_TCG *) tcg,
@@ -66,7 +66,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(
                 .Header.EventType = EV_IPL,
         };
 
-        CopyMem(tcg_event->Event, description, desc_len);
+        memcpy(tcg_event->Event, description, desc_len);
 
         return tcg->HashLogExtendEvent(
                         tcg,
index daa76388627fd5d862232ecba96cf1a2a51da31e..f9bd57f0ce5e658cddffb3a79700938e1390daaf 100644 (file)
@@ -119,12 +119,12 @@ struct PeSectionHeader {
 
 static inline BOOLEAN verify_dos(const struct DosFileHeader *dos) {
         assert(dos);
-        return CompareMem(dos->Magic, DOS_FILE_MAGIC, STRLEN(DOS_FILE_MAGIC)) == 0;
+        return memcmp(dos->Magic, DOS_FILE_MAGIC, STRLEN(DOS_FILE_MAGIC)) == 0;
 }
 
 static inline BOOLEAN verify_pe(const struct PeFileHeader *pe, BOOLEAN allow_compatibility) {
         assert(pe);
-        return CompareMem(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
+        return memcmp(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
                (pe->FileHeader.Machine == TARGET_MACHINE_TYPE ||
                 (allow_compatibility && pe->FileHeader.Machine == TARGET_MACHINE_TYPE_COMPATIBILITY)) &&
                pe->FileHeader.NumberOfSections > 0 &&
@@ -154,7 +154,7 @@ static void locate_sections(
                 const struct PeSectionHeader *sect = section_table + i;
 
                 for (UINTN j = 0; sections[j]; j++) {
-                        if (CompareMem(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
+                        if (memcmp(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
                                 continue;
 
                         if (addrs)
index 2ff8299fa65d1f55a94003411bba6dbe38fb512d..a9ee2736736ff1a4c452b57854bd81cf8bb0afdf 100644 (file)
@@ -223,7 +223,7 @@ static void validate_sha256(void) {
                 sha256_process_bytes(array[i].string, strlen8(array[i].string), &hash);
                 sha256_finish_ctx(&hash, result);
 
-                assert(CompareMem(result, array[i].hash, HASH_VALUE_SIZE) == 0);
+                assert(memcmp(result, array[i].hash, HASH_VALUE_SIZE) == 0);
         }
 
 #endif
index 40f615b2b363d1fdc370330e222a65fe4f094d32..36becafa0836e71cb90d1b991f5ec287ea8fa29e 100644 (file)
@@ -68,28 +68,28 @@ 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 */
-                CopyMem(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
+                memcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
                 p += initrd_size;
 
                 pad = ALIGN_TO(initrd_size, 4) - initrd_size;
                 if (pad > 0)  {
-                        ZeroMem(p, pad);
+                        memset(p, 0, pad);
                         p += pad;
                 }
         }
 
         if (credential_initrd) {
-                CopyMem(p, credential_initrd, credential_initrd_size);
+                memcpy(p, credential_initrd, credential_initrd_size);
                 p += credential_initrd_size;
         }
 
         if (global_credential_initrd) {
-                CopyMem(p, global_credential_initrd, global_credential_initrd_size);
+                memcpy(p, global_credential_initrd, global_credential_initrd_size);
                 p += global_credential_initrd_size;
         }
 
         if (sysext_initrd) {
-                CopyMem(p, sysext_initrd, sysext_initrd_size);
+                memcpy(p, sysext_initrd, sysext_initrd_size);
                 p += sysext_initrd_size;
         }
 
index 2827dae8ff914840f013de342c6c519396ee0cdc..83e03fa835d4171929079db218d26314ece78d85 100644 (file)
@@ -117,7 +117,7 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value
         /* Make sure a terminating NUL is available at the end */
         val = xallocate_pool(size + sizeof(CHAR16));
 
-        CopyMem(val, buf, size);
+        memcpy(val, buf, size);
         val[size / sizeof(CHAR16) - 1] = 0; /* NUL terminate */
 
         *value = val;
@@ -397,7 +397,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C
                 return err;
 
         /* Note that handle->Read() changes size to reflect the actually bytes read. */
-        ZeroMem(buf + size, extra);
+        memset(buf + size, 0, extra);
 
         *ret = TAKE_PTR(buf);
         if (ret_size)
@@ -566,7 +566,7 @@ CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) {
         n = xallocate_pool(sz + 1);
 
         if (sz > 0)
-                CopyMem(n, p, sz);
+                memcpy(n, p, sz);
         n[sz] = 0;
 
         return n;
index f73b5eeb202ff609789034c86c5aee45fce1dd62..bc82768715f6de4c1240546814aa2bd75c3b3ea5 100644 (file)
@@ -19,7 +19,7 @@ static EFI_DEVICE_PATH *path_chop(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node)
         UINTN len = (UINT8 *) node - (UINT8 *) path;
         EFI_DEVICE_PATH *chopped = xallocate_pool(len + END_DEVICE_PATH_LENGTH);
 
-        CopyMem(chopped, path, len);
+        memcpy(chopped, path, len);
         SetDevicePathEndNode((EFI_DEVICE_PATH *) ((UINT8 *) chopped + len));
 
         return chopped;
@@ -35,7 +35,7 @@ static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_
         h = &gpt_header_buffer->gpt_header;
 
         /* Some superficial validation of the GPT header */
-        if (CompareMem(&h->Header.Signature, "EFI PART", sizeof(h->Header.Signature)) != 0)
+        if (memcmp(&h->Header.Signature, "EFI PART", sizeof(h->Header.Signature)) != 0)
                 return FALSE;
 
         if (h->Header.HeaderSize < 92 || h->Header.HeaderSize > 512)
@@ -123,12 +123,12 @@ static EFI_STATUS try_gpt(
 
                 entry = (EFI_PARTITION_ENTRY*) ((UINT8*) entries + gpt.gpt_header.SizeOfPartitionEntry * i);
 
-                if (CompareMem(&entry->PartitionTypeGUID, XBOOTLDR_GUID, sizeof(entry->PartitionTypeGUID)) != 0)
+                if (memcmp(&entry->PartitionTypeGUID, XBOOTLDR_GUID, sizeof(entry->PartitionTypeGUID)) != 0)
                         continue;
 
                 /* Let's use memcpy(), in case the structs are not aligned (they really should be though) */
-                CopyMem(&start, &entry->StartingLBA, sizeof(start));
-                CopyMem(&end, &entry->EndingLBA, sizeof(end));
+                memcpy(&start, &entry->StartingLBA, sizeof(start));
+                memcpy(&end, &entry->EndingLBA, sizeof(end));
 
                 if (end < start) /* Bogus? */
                         continue;
@@ -138,7 +138,7 @@ static EFI_STATUS try_gpt(
                 ret_hd->PartitionSize = end - start + 1;
                 ret_hd->MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;
                 ret_hd->SignatureType = SIGNATURE_TYPE_GUID;
-                CopyMem(ret_hd->Signature, &entry->UniquePartitionGUID, sizeof(ret_hd->Signature));
+                memcpy(ret_hd->Signature, &entry->UniquePartitionGUID, sizeof(ret_hd->Signature));
 
                 return EFI_SUCCESS;
         }
@@ -227,7 +227,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
 
                 /* Patch in the data we found */
                 EFI_DEVICE_PATH *xboot_path = ASSERT_SE_PTR(DuplicateDevicePath(partition_path));
-                CopyMem((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
+                memcpy((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
                 *ret_device_path = xboot_path;
                 return EFI_SUCCESS;
         }
index 59d63e8e5dac6e906d0ab516fb636ff6c40e6d50..bb9e779dd2328c2a4e6dbb08f9dbfcd68f0d5624 100644 (file)
@@ -77,7 +77,6 @@
         #define static_assert _Static_assert
         #define assert_se(expr) ({ _likely_(expr) ? VOID_0 : efi_assert(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); })
 
-        #define memcpy(a, b, c) CopyMem((a), (b), (c))
         #define free(a) FreePool(a)
 #endif
 
index 0577a24920b2f4ae2c6311f3767c4a0c21577a1f..6fcb37a7d9e2ae5ff5fa70b004598ce54cc7f857 100644 (file)
 
 /* Written by Ulrich Drepper <drepper@redhat.com>, 2007.  */
 
-#ifndef SD_BOOT
-#include <string.h>
+#ifdef SD_BOOT
+#  include "efi-string.h"
+#else
+#  include <string.h>
 #endif
 
 #include "macro-fundamental.h"
index d7a67356abef06fd9160d86e590b71d27d01aa64..8048a07f737019425e43d0ca83c2c15ae752e60d 100644 (file)
@@ -18,7 +18,6 @@
 #  define strcasecmp strcasecmp16
 #  define strncasecmp strncasecmp16
 #  define STR_C(str)       (L ## str)
-#  define memcmp(a, b, n)  CompareMem(a, b, n)
 #else
 #  define STR_C(str)       (str)
 #endif