* [PATCH] readelf: Fix deref-of-null in handle_core_item()
@ 2024-03-29 22:47 Maks Mishin
0 siblings, 0 replies; 2+ messages in thread
From: Maks Mishin @ 2024-03-29 22:47 UTC (permalink / raw)
To: elfutils-devel; +Cc: Maks Mishin
Return value of a function 'gelf_getehdr' is dereferenced
without checking for NULL, but it is usually checked for this function.
Found by RASU JSC.
Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
src/readelf.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/readelf.c b/src/readelf.c
index 0e931184..f2ec358f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12440,6 +12440,13 @@ handle_core_item (Elf *core, const Ebl_Core_Item *item, const void *desc,
field went into the high half of USEC. */
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = gelf_getehdr (core, &ehdr_mem);
+
+ if (ehdr == NULL)
+ {
+ error (0, 0, _("cannot read ELF header: %s"), elf_errmsg (-1));
+ return;
+ }
+
if (likely (ehdr->e_ident[EI_DATA] == ELFDATA2MSB))
usec >>= 32;
else
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] readelf: Fix deref-of-null in handle_core_item()
@ 2024-04-01 16:02 Maks Mishin
0 siblings, 0 replies; 2+ messages in thread
From: Maks Mishin @ 2024-04-01 16:02 UTC (permalink / raw)
To: elfutils-devel; +Cc: Maks Mishin
Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
src/readelf.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/readelf.c b/src/readelf.c
index 0e931184..495db13e 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12440,6 +12440,13 @@ handle_core_item (Elf *core, const Ebl_Core_Item *item, const void *desc,
field went into the high half of USEC. */
GElf_Ehdr ehdr_mem;
GElf_Ehdr *ehdr = gelf_getehdr (core, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ error (EXIT_FAILURE, 0,
+ _("cannot read ELF header: %s"), elf_errmsg (-1));
+ return;
+ }
+
if (likely (ehdr->e_ident[EI_DATA] == ELFDATA2MSB))
usec >>= 32;
else
--
2.30.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-01 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-29 22:47 [PATCH] readelf: Fix deref-of-null in handle_core_item() Maks Mishin
2024-04-01 16:02 Maks Mishin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).