diff options
| -rw-r--r-- | include/sbat.h | 7 | ||||
| -rw-r--r-- | pe.c | 15 | ||||
| -rw-r--r-- | sbat.c | 26 |
3 files changed, 24 insertions, 24 deletions
diff --git a/include/sbat.h b/include/sbat.h index c49c645e..c34ad319 100644 --- a/include/sbat.h +++ b/include/sbat.h @@ -15,12 +15,7 @@ struct sbat_entry { const CHAR8 *vendor_url; }; -struct sbat { - unsigned int size; - struct sbat_entry **entries; -}; - -EFI_STATUS parse_sbat(char *sbat_base, size_t sbat_size, struct sbat *sbat); +EFI_STATUS parse_sbat(char *sbat_base, size_t sbat_size, size_t *sbats, struct sbat_entry ***sbat); #endif /* !SBAT_H_ */ // vim:fenc=utf-8:tw=75:noet @@ -1041,7 +1041,8 @@ handle_image (void *data, unsigned int datasize, if (secure_mode ()) { unsigned int i; EFI_STATUS efi_status; - struct sbat sbat = { 0 }; + size_t n; + struct sbat_entry **entries; struct sbat_entry *entry = NULL; if (SBATBase && SBATSize) { @@ -1057,7 +1058,7 @@ handle_image (void *data, unsigned int datasize, CopyMem(sbat_data, SBATBase, SBATSize); sbat_data[SBATSize] = '\0'; - efi_status = parse_sbat(sbat_data, sbat_size, &sbat); + efi_status = parse_sbat(sbat_data, sbat_size, &n, &entries); if (EFI_ERROR(efi_status)) { perror(L"SBAT data not correct: %r\n", efi_status); @@ -1065,8 +1066,8 @@ handle_image (void *data, unsigned int datasize, } dprint(L"SBAT data\n"); - for (i = 0; i < sbat.size; i++) { - entry = sbat.entries[i]; + for (i = 0; i < n; i++) { + entry = entries[i]; dprint(L"%a, %a, %a, %a, %a, %a\n", entry->component_name, entry->component_generation, @@ -1083,9 +1084,9 @@ handle_image (void *data, unsigned int datasize, efi_status = verify_buffer(data, datasize, &context, sha256hash, sha1hash); - if (sbat.entries) - for (i = 0; i < sbat.size; i++) - FreePool(sbat.entries[i]); + if (entries) + for (i = 0; i < n; i++) + FreePool(entries[i]); if (EFI_ERROR(efi_status)) { if (verbose) @@ -68,21 +68,24 @@ error: } EFI_STATUS -parse_sbat(char *sbat_base, size_t sbat_size, struct sbat *sbat) +parse_sbat(char *sbat_base, size_t sbat_size, size_t *sbats, struct sbat_entry ***sbat) { CHAR8 *current = (CHAR8 *) sbat_base; CHAR8 *end = (CHAR8 *) sbat_base + sbat_size - 1; EFI_STATUS efi_status = EFI_SUCCESS; struct sbat_entry *entry; - struct sbat_entry **entries; - unsigned int i; + struct sbat_entry **entries = NULL; + unsigned int i = 0; - if (!sbat_base || !sbat || sbat_size == 0) + if (!sbat_base || sbat_size == 0 || !sbats || !sbat) return EFI_INVALID_PARAMETER; if (current == end) return EFI_INVALID_PARAMETER; + *sbats = 0; + *sbat = 0; + do { entry = NULL; efi_status = parse_sbat_entry(¤t, end, &entry); @@ -96,24 +99,25 @@ parse_sbat(char *sbat_base, size_t sbat_size, struct sbat *sbat) if (entry) { entries = ReallocatePool( - sbat->entries, sbat->size * sizeof(entry), - (sbat->size + 1) * sizeof(entry)); + entries, i * sizeof(entry), + (i + 1) * sizeof(entry)); if (!entries) { efi_status = EFI_OUT_OF_RESOURCES; goto error; } - sbat->entries = entries; - sbat->entries[sbat->size] = entry; - sbat->size++; + entries[i++] = entry; } } while (entry && *current != '\0'); + *sbats = i; + *sbat = entries; + return efi_status; error: perror(L"Failed to parse SBAT data: %r\n", efi_status); - for (i = 0; i < sbat->size; i++) - FreePool(sbat->entries[i]); + while (i) + FreePool(entries[i--]); return efi_status; } |
