Static analyzer reported:
Return value of a function 'gelf_getehdr' is dereferenced at readelf.c:12443
without checking for NULL, but it is usually checked for this function (53/54).

Corrections explained:
- Added a NULL check for the ehdr variable

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.morya...@gmail.com>
---
 src/readelf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/readelf.c b/src/readelf.c
index 6526db07..3bdfb391 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -12440,6 +12440,11 @@ 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 (unlikely(ehdr == NULL))
+         {
+               fprintf(stderr, "Failed to get ELF header\n");
+               return;
+         }
          if (likely (ehdr->e_ident[EI_DATA] == ELFDATA2MSB))
            usec >>= 32;
          else
-- 
2.30.2

Reply via email to