From: Lukas Fink Date: Sun, 5 Jan 2025 08:24:11 +0000 (-0600) Subject: commands/file: Fix NULL dereference in the knetbsd tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7161e2437dda654c69b930edb2fd18bbfe5c1f05;p=thirdparty%2Fgrub.git commands/file: Fix NULL dereference in the knetbsd tests 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 Signed-off-by: Lukas Fink Reviewed-by: Ross Philipson Reviewed-by: Daniel Kiper --- diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c index 7c13e976b..19602d757 100644 --- a/grub-core/commands/file.c +++ b/grub-core/commands/file.c @@ -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;