efi_loader: efidebug, avoid illegal memory access
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Wed, 29 Apr 2020 18:21:39 +0000 (20:21 +0200)
committerHeinrich Schuchardt <xypron.glpk@gmx.de>
Thu, 30 Apr 2020 08:25:07 +0000 (10:25 +0200)
For EFI_PERSISTENT_MEMORY_TYPE the 'efidebug memmap' command produces an
illegal memory access.

* Add the missing descriptive string for EFI_PERSISTENT_MEMORY_TYPE.
* Replace the check for EFI_MAX_MEMORY_TYPE by the ARRAY_SIZE() macro.

Reported-by: Coverity (CID 300336)
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
cmd/efidebug.c

index 7ff2ce4ce1c27d29a7949487a3971c4b7b2b9be2..53cb3cbfaf1608ebc841cc87a9a76b4f4cb036a9 100644 (file)
@@ -395,6 +395,7 @@ static const char * const efi_mem_type_string[] = {
        [EFI_MMAP_IO] = "IO",
        [EFI_MMAP_IO_PORT] = "IO PORT",
        [EFI_PAL_CODE] = "PAL",
+       [EFI_PERSISTENT_MEMORY_TYPE] = "PERSISTENT",
 };
 
 static const struct efi_mem_attrs {
@@ -482,7 +483,7 @@ static int do_efi_show_memmap(cmd_tbl_t *cmdtp, int flag,
        printf("================ %.*s %.*s ==========\n",
               EFI_PHYS_ADDR_WIDTH, sep, EFI_PHYS_ADDR_WIDTH, sep);
        for (i = 0, map = memmap; i < map_size / sizeof(*map); map++, i++) {
-               if (map->type < EFI_MAX_MEMORY_TYPE)
+               if (map->type < ARRAY_SIZE(efi_mem_type_string))
                        type = efi_mem_type_string[map->type];
                else
                        type = "(unknown)";