public inbox for debugedit@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: debugedit@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [COMMITTED] debugedit: Guard against NULL names returned by by strptr
Date: Thu, 24 Mar 2022 18:09:23 +0100	[thread overview]
Message-ID: <20220324170923.28445-1-mark@klomp.org> (raw)

	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


                 reply	other threads:[~2022-03-24 17:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220324170923.28445-1-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=debugedit@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).