[PATCH] strip: Add check for elf_begin() result

Maks Mishin maks.mishinfz@gmail.com
Fri Apr 5 18:53:03 GMT 2024


Return value of a function 'elf_begin' is dereferenced at strip.c:1166
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/strip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/strip.c b/src/strip.c
index 6436443d..ebab4866 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1153,7 +1153,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
     {
       /* Also create an ELF descriptor for the debug file */
       debugelf = elf_begin (debug_fd, ELF_C_WRITE, NULL);
-      if (unlikely (gelf_newehdr (debugelf, gelf_getclass (elf)) == 0))
+      ELF_CHECK (debugelf != NULL, _("cannot create ELF descriptor: %s"));
+
+	  if (unlikely (gelf_newehdr (debugelf, gelf_getclass (elf)) == 0))
 	{
 	  error (0, 0, _("cannot create new ehdr for file '%s': %s"),
 		 debug_fname, elf_errmsg (-1));
-- 
2.30.2



More information about the Elfutils-devel mailing list