efi_loader: avoid NULL dereference in efi_get_memory_map()
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Mon, 6 Aug 2018 20:28:18 +0000 (22:28 +0200)
committerAlexander Graf <agraf@suse.de>
Mon, 20 Aug 2018 12:41:09 +0000 (14:41 +0200)
We should only dereference parameter memory_map_size after checking that
it is valid.

Fixes: 8e835554b36b ("efi_loader: check parameters of GetMemoryMap")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
lib/efi_loader/efi_memory.c

index 4b6269f35e11db2cdef00081086544a7cbe5abd7..3ee1079e75e65bd1c41bd5c3d92beea7c3d216e9 100644 (file)
@@ -457,11 +457,13 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
        efi_uintn_t map_size = 0;
        int map_entries = 0;
        struct list_head *lhandle;
-       efi_uintn_t provided_map_size = *memory_map_size;
+       efi_uintn_t provided_map_size;
 
        if (!memory_map_size)
                return EFI_INVALID_PARAMETER;
 
+       provided_map_size = *memory_map_size;
+
        list_for_each(lhandle, &efi_mem)
                map_entries++;