bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] commands/file: Fix possible null dereference


From: Lukas Fink
Subject: [PATCH 3/3] commands/file: Fix possible null dereference
Date: Sun, 30 Aug 2020 02:59:24 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0

> I found a few bugs in the grub-file utility and the corresponding
> command.

The last bug I found is that a null pointer dereference can happen in
the knetbsd tests when the tested file doesn't have a valid ELF header.

Greetings

Lukas Fink

>From a2533eac007b1e50c1c8ef2acc36b44e08a9fbc1 Mon Sep 17 00:00:00 2001
From: Lukas Fink <lukas.fink1@gmail.com>
Date: Sun, 30 Aug 2020 01:00:10 +0200
Subject: [PATCH 3/3] commands/file: Fix possible null dereference

that happened in the knetbsd tests, when grub_elf_file returned null on the
given file. This occured for example when the file had no valid elf header.
---
 grub-core/commands/file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/grub-core/commands/file.c b/grub-core/commands/file.c
index 2c4718cb2..18ecdc6f2 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)
+         break;
        if (elf->ehdr.ehdr32.e_type != grub_cpu_to_le16_compile_time (ET_EXEC)
            || elf->ehdr.ehdr32.e_ident[EI_DATA] != ELFDATA2LSB)
          break;
-- 
2.28.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]