systemd-boot: fix off-by-one buffer overrun
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 7 Mar 2018 07:51:09 +0000 (08:51 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 7 Mar 2018 08:03:23 +0000 (09:03 +0100)
We'd allocate a buffer of some size and then write zero to the byte one after.

src/boot/efi/util.c

index bff8ba8..cd75c13 100644 (file)
@@ -327,16 +327,15 @@ EFI_STATUS file_read(EFI_FILE_HANDLE dir, CHAR16 *name, UINTN off, UINTN size, C
                         return err;
         }
 
-        buf = AllocatePool(size);
+        buf = AllocatePool(size + 1);
         err = uefi_call_wrapper(handle->Read, 3, handle, &size, buf);
         if (!EFI_ERROR(err)) {
                 buf[size] = '\0';
                 *content = buf;
                 if (content_size)
                         *content_size = size;
-        } else {
+        } else
                 FreePool(buf);
-        }
 
         uefi_call_wrapper(handle->Close, 1, handle);
         return err;