]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
commands/file: Fix NULL dereference in the knetbsd tests
authorLukas Fink <lukas.fink1@gmail.com>
Sun, 5 Jan 2025 08:24:11 +0000 (02:24 -0600)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 26 Feb 2025 18:34:57 +0000 (19:34 +0100)
The pointer returned by grub_elf_file() is not checked to verify it is
not NULL before use. A NULL pointer may be returned when the given file
does not have a valid ELF header.

Fixes: https://savannah.gnu.org/bugs/?61960
Signed-off-by: Glenn Washburn <development@efficientek.com>
Signed-off-by: Lukas Fink <lukas.fink1@gmail.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/commands/file.c

index 7c13e976b505b3bf7982dcbd553a77666c1797e4..19602d75786b6850186ec1f0e3f35cb9216edc60 100644 (file)
@@ -306,6 +306,8 @@ grub_cmd_file (grub_extcmd_context_t ctxt, int argc, char **args)
 
        elf = grub_elf_file (file, file->name);
 
+       if (elf == NULL)
+         break;
        if (elf->ehdr.ehdr32.e_type != grub_cpu_to_le16_compile_time (ET_EXEC)
            || elf->ehdr.ehdr32.e_ident[EI_DATA] != ELFDATA2LSB)
          break;