Make sure to not crash and just return NULL (failure) if gelf_newphdr
gets a NULL Elf handle like other gelf functions do.

        * libelf/gelf_newphdr.c (gelf_newphdr): Check elf is not NULL.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libelf/gelf_newphdr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libelf/gelf_newphdr.c b/libelf/gelf_newphdr.c
index 84aad781f541..193599c9ae04 100644
--- a/libelf/gelf_newphdr.c
+++ b/libelf/gelf_newphdr.c
@@ -40,6 +40,9 @@
 void *
 gelf_newphdr ( Elf *elf, size_t phnum)
 {
+  if (elf == NULL)
+    return NULL;
+
   return (elf->class == ELFCLASS32
          ? (void *) INTUSE(elf32_newphdr) (elf, phnum)
          : (void *) INTUSE(elf64_newphdr) (elf, phnum));
-- 
2.56.0

Reply via email to