summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Jones <pjones@redhat.com>2021-02-09 20:02:26 -0500
committerPeter Jones <pjones@redhat.com>2021-02-13 11:02:59 -0500
commit6b8ef61a1aa9c69aecb6a22cf79ddece727273e2 (patch)
tree916ea7f3aaaa80a75523cfbdc3a5bc790537a656
parentee8f7ed3326cf680452a4eaf68208f5feb6ddb50 (diff)
downloadefi-boot-shim-6b8ef61a1aa9c69aecb6a22cf79ddece727273e2.tar.gz
efi-boot-shim-6b8ef61a1aa9c69aecb6a22cf79ddece727273e2.zip
SBAT: parse a copy of the table that's got a NUL at the end
Right now we allocate the PE file's contents in RW memory, but hopefully that won't always be the case. Our SBAT parsing, however, very much expects to be able to edit it. We also don't actually know that shim's .sbat section is loaded r/w, so we can't necessarily write there. This patch copies the SBAT data to its own buffer, plus one NUL byte at the end, so we can always be sure that will work. Signed-off-by: Peter Jones <pjones@redhat.com>
-rw-r--r--pe.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/pe.c b/pe.c
index f3e93490..acbf82e8 100644
--- a/pe.c
+++ b/pe.c
@@ -1045,7 +1045,19 @@ handle_image (void *data, unsigned int datasize,
struct sbat_entry *entry = NULL;
if (SBATBase && SBATSize) {
- res = parse_sbat(SBATBase, SBATSize, buffer, &sbat);
+ char *sbat_data;
+ size_t sbat_size;
+
+ sbat_size = SBATSize + 1;
+ sbat_data = AllocatePool(sbat_size);
+ if (!sbat_data) {
+ console_print(L"Failed to allocate SBAT buffer\n");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ CopyMem(sbat_data, SBATBase, SBATSize);
+ sbat_data[SBATSize] = '\0';
+
+ res = parse_sbat(sbat_data, sbat_size, buffer, &sbat);
if (res < 0) {
console_print(L"SBAT data not correct: %r\n", res);
return EFI_UNSUPPORTED;