Hi Anton,
On Thu, Feb 27, 2025 at 10:28:20PM +0100, Mark Wielaard wrote:
> > diff --git a/src/unstrip.c b/src/unstrip.c
> > index d70053de..35c04700 100644
> > --- a/src/unstrip.c
> > +++ b/src/unstrip.c
> > @@ -1974,6 +1974,9 @@ more sections in stripped file than debug file --
> > arguments reversed?"));
> > }
> > }
> >
> > + if (symstrdata == NULL)
> > + error_exit (0, "Failed to get data from symbol string table");
> > +
> > if (dwelf_strtab_finalize (symstrtab, symstrdata) == NULL)
> > error_exit (0, "Not enough memory to create symbol table");
>
> If you check this why not at the point where elf_getdata is called
> (symstrdata is assigned?). And then you should also check the other
> elf_getdata call at the same time here:
>
> symdata = elf_getdata (unstripped_symtab, NULL);
> symstrdata = elf_getdata (unstripped_strtab, NULL);
I implemented that and pushed as attached.
Cheers,
Mark
>From 50586ba4a99c06674962fe3bdd685088ab6808e1 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <m...@klomp.org>
Date: Wed, 30 Apr 2025 00:22:59 +0200
Subject: [PATCH 3/3] unstrip: Check symtab and strtab sections have data
before use.
* src/unstrip.c (copy_elided_sections): Check elf_getdata result
for symtab and strtab sections.
Suggested-by: Anton Moryakov <ant.v.morya...@gmail.com>
Signed-off-by: Mark Wielaard <m...@klomp.org>
---
src/unstrip.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/unstrip.c b/src/unstrip.c
index d70053def292..0ae76f77e9ae 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -1946,7 +1946,13 @@ more sections in stripped file than debug file --
arguments reversed?"));
/* Now we are ready to write the new symbol table. */
symdata = elf_getdata (unstripped_symtab, NULL);
+ if (symdata == NULL)
+ error_exit (0, "Failed to get data from symbol table: %s",
+ elf_errmsg (-1));
symstrdata = elf_getdata (unstripped_strtab, NULL);
+ if (symstrdata == NULL)
+ error_exit (0, "Failed to get data from symbol string table: %s",
+ elf_errmsg (-1));
Elf_Data *shndxdata = NULL; /* XXX */
/* If symtab and the section header table share the string table
--
2.49.0