sd-boot: Use StrSize where it makes sense
This commit is contained in:
+10
-8
@@ -2284,7 +2284,7 @@ static EFI_STATUS image_start(
|
||||
goto out_unload;
|
||||
}
|
||||
loaded_image->LoadOptions = options;
|
||||
loaded_image->LoadOptionsSize = (StrLen(loaded_image->LoadOptions)+1) * sizeof(CHAR16);
|
||||
loaded_image->LoadOptionsSize = StrSize(loaded_image->LoadOptions);
|
||||
|
||||
#if ENABLE_TPM
|
||||
/* Try to log any options to the TPM, especially to catch manually edited options */
|
||||
@@ -2332,28 +2332,30 @@ static VOID config_free(Config *config) {
|
||||
}
|
||||
|
||||
static VOID config_write_entries_to_variable(Config *config) {
|
||||
_cleanup_freepool_ CHAR16 *buffer = NULL;
|
||||
_cleanup_freepool_ CHAR8 *buffer = NULL;
|
||||
UINTN sz = 0;
|
||||
CHAR16 *p;
|
||||
CHAR8 *p;
|
||||
|
||||
assert(config);
|
||||
|
||||
for (UINTN i = 0; i < config->entry_count; i++)
|
||||
sz += StrLen(config->entries[i]->id) + 1;
|
||||
sz += StrSize(config->entries[i]->id);
|
||||
|
||||
p = buffer = AllocatePool(sz * sizeof(CHAR16));
|
||||
p = buffer = AllocatePool(sz);
|
||||
|
||||
for (UINTN i = 0; i < config->entry_count; i++) {
|
||||
UINTN l;
|
||||
|
||||
l = StrLen(config->entries[i]->id) + 1;
|
||||
CopyMem(p, config->entries[i]->id, l * sizeof(CHAR16));
|
||||
l = StrSize(config->entries[i]->id);
|
||||
CopyMem(p, config->entries[i]->id, l);
|
||||
|
||||
p += l;
|
||||
}
|
||||
|
||||
assert(p == buffer + sz);
|
||||
|
||||
/* Store the full list of discovered entries. */
|
||||
(void) efivar_set_raw(LOADER_GUID, L"LoaderEntries", buffer, (UINT8 *) p - (UINT8 *) buffer, 0);
|
||||
(void) efivar_set_raw(LOADER_GUID, L"LoaderEntries", buffer, sz, 0);
|
||||
}
|
||||
|
||||
EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
|
||||
|
||||
@@ -188,8 +188,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(const EFI_TCG *tcg, UINT32 p
|
||||
assert(tcg);
|
||||
assert(description);
|
||||
|
||||
desc_len = (StrLen(description) + 1) * sizeof(CHAR16);
|
||||
|
||||
desc_len = StrSize(description);
|
||||
tcg_event = AllocateZeroPool(desc_len + sizeof(TCG_PCR_EVENT));
|
||||
|
||||
if (!tcg_event)
|
||||
@@ -222,14 +221,13 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(const EFI_TCG2 *tcg, UINT32
|
||||
assert(tcg);
|
||||
assert(description);
|
||||
|
||||
desc_len = StrLen(description) * sizeof(CHAR16);
|
||||
|
||||
tcg_event = AllocateZeroPool(sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len + 1);
|
||||
desc_len = StrSize(description);
|
||||
tcg_event = AllocateZeroPool(sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len);
|
||||
|
||||
if (!tcg_event)
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
|
||||
tcg_event->Size = sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len + 1;
|
||||
tcg_event->Size = sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len;
|
||||
tcg_event->Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER);
|
||||
tcg_event->Header.HeaderVersion = EFI_TCG2_EVENT_HEADER_VERSION;
|
||||
tcg_event->Header.PCRIndex = pcrindex;
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ EFI_STATUS efivar_set(const EFI_GUID *vendor, const CHAR16 *name, const CHAR16 *
|
||||
assert(vendor);
|
||||
assert(name);
|
||||
|
||||
return efivar_set_raw(vendor, name, value, value ? (StrLen(value) + 1) * sizeof(CHAR16) : 0, flags);
|
||||
return efivar_set_raw(vendor, name, value, value ? StrSize(value) : 0, flags);
|
||||
}
|
||||
|
||||
EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, UINT32 flags) {
|
||||
|
||||
Reference in New Issue
Block a user