public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] unstrip: Fix off by one array access with unstripped_strent.
@ 2016-07-11  8:00 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-07-11  8:00 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

On Wed, 2016-07-06 at 21:43 +0200, Mark Wielaard wrote:
> When configuring with --enable-sanitize-undefined the latest GCC found
> an array out of bounds access when running the un-strip-strmerge.sh test.
> We keep an array of section names. But skipped section zero, since it
> didn't have a name. We should however not actually skip the first array
> index (zero) when storing and reading the names.

I pushed this to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] unstrip: Fix off by one array access with unstripped_strent.
@ 2016-07-06 19:43 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-07-06 19:43 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]

When configuring with --enable-sanitize-undefined the latest GCC found
an array out of bounds access when running the un-strip-strmerge.sh test.
We keep an array of section names. But skipped section zero, since it
didn't have a name. We should however not actually skip the first array
index (zero) when storing and reading the names.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog | 5 +++++
 src/unstrip.c | 6 +++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 21fc7d5..fbe4afc 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2016-07-06  Mark Wielaard  <mjw@redhat.com>
+
+	* unstrip.c (copy_elided_sections): Use unstripped_strent[] from
+	index zero, instead of one.
+
 2016-06-28  Richard Henderson <rth@redhat.com>
 
 	* elflint.c (valid_e_machine): Add EM_BPF.
diff --git a/src/unstrip.c b/src/unstrip.c
index 85e0a1d..adeb599 100644
--- a/src/unstrip.c
+++ b/src/unstrip.c
@@ -1761,8 +1761,8 @@ more sections in stripped file than debug file -- arguments reversed?"));
 	      GElf_Shdr mem;
 	      GElf_Shdr *hdr = gelf_getshdr (sec, &mem);
 	      const char *name = get_section_name (i + 1, hdr, shstrtab);
-	      unstripped_strent[i + 1] = ebl_strtabadd (symstrtab, name, 0);
-	      ELF_CHECK (unstripped_strent[i + 1] != NULL,
+	      unstripped_strent[i] = ebl_strtabadd (symstrtab, name, 0);
+	      ELF_CHECK (unstripped_strent[i] != NULL,
 			 _("cannot add section name to string table: %s"));
 	    }
 
@@ -1785,7 +1785,7 @@ more sections in stripped file than debug file -- arguments reversed?"));
 	      Elf_Scn *sec = elf_getscn (unstripped, i + 1);
 	      GElf_Shdr mem;
 	      GElf_Shdr *hdr = gelf_getshdr (sec, &mem);
-	      shdr->sh_name = ebl_strtaboffset (unstripped_strent[i + 1]);
+	      shdr->sh_name = ebl_strtaboffset (unstripped_strent[i]);
 	      update_shdr (sec, hdr);
 	    }
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-07-11  8:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-11  8:00 [PATCH] unstrip: Fix off by one array access with unstripped_strent Mark Wielaard
  -- strict thread matches above, loose matches on Subject: below --
2016-07-06 19:43 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).