* [COMMITTED] debugedit: Guard against NULL names returned by by strptr
@ 2022-03-24 17:09 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2022-03-24 17:09 UTC (permalink / raw)
To: debugedit; +Cc: Mark Wielaard
debugedit.c (edit_dwarf2): Check name is not NULL before
calling strncmp.
(main): Check name is not NULL before calling strcmp.
This is unlikely to happen, except when the ELF file is corrupt.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
tools/debugedit.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 642b29d..e734dd7 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -2586,7 +2586,8 @@ edit_dwarf2 (DSO *dso)
const char *name = strptr (dso, dso->ehdr.e_shstrndx,
dso->shdr[i].sh_name);
- if (strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0)
+ if (name != NULL
+ && strncmp (name, ".debug_", sizeof (".debug_") - 1) == 0)
{
for (j = 0; debug_sections[j].name; ++j)
if (strcmp (name, debug_sections[j].name) == 0)
@@ -2642,9 +2643,11 @@ edit_dwarf2 (DSO *dso)
}
else if (dso->ehdr.e_type == ET_REL
&& ((dso->shdr[i].sh_type == SHT_REL
+ && name != NULL
&& strncmp (name, ".rel.debug_",
sizeof (".rel.debug_") - 1) == 0)
|| (dso->shdr[i].sh_type == SHT_RELA
+ && name != NULL
&& strncmp (name, ".rela.debug_",
sizeof (".rela.debug_") - 1) == 0)))
{
@@ -3467,13 +3470,13 @@ main (int argc, char *argv[])
case SHT_PROGBITS:
name = strptr (dso, dso->ehdr.e_shstrndx, dso->shdr[i].sh_name);
/* TODO: Handle stabs */
- if (strcmp (name, ".stab") == 0)
+ if (name != NULL && strcmp (name, ".stab") == 0)
{
error (0, 0, "Stabs debuginfo not supported: %s", file);
break;
}
if (!(do_build_id && no_recompute_build_id && !base_dir && !dest_dir)
- && strcmp (name, ".debug_info") == 0)
+ && name != NULL && strcmp (name, ".debug_info") == 0)
edit_dwarf2 (dso);
break;
--
2.18.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-24 17:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 17:09 [COMMITTED] debugedit: Guard against NULL names returned by by strptr Mark Wielaard
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).