public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elfcompress: Add sanity checks to make sure to not override variable
@ 2022-05-10 10:35 Mark Wielaard
  2022-05-14 13:14 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2022-05-10 10:35 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

The process_file code is a little tricky. Add sanity checks to make
sure shstrtab_name, shstrtab_newname and symstrents are only set once.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog     |  5 +++++
 src/elfcompress.c | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/ChangeLog b/src/ChangeLog
index b978f9ef..d08381e8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2022-05-10  Mark Wielaard  <mark@klomp.org>
+
+	* elfcompress.c (process_file): Sanity check shstrtab_name,
+	shstrtab_newname and symstrents are only set once.
+
 2022-05-09  Mark Wielaard  <mark@klomp.org>
 
 	* strip.c (remove_debug_relocations): Check gelf_getshdr, gelf_getrela,
diff --git a/src/elfcompress.c b/src/elfcompress.c
index 92f2fac8..6f18e47d 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -730,6 +730,15 @@ process_file (const char *fname)
 			{
 			  shstrtab_size = size;
 			  shstrtab_compressed = T_COMPRESS_GNU;
+			  if (shstrtab_name != NULL
+			      || shstrtab_newname != NULL)
+			    {
+			      error (0, 0, "Internal error,"
+					   " shstrtab_name already set,"
+					   " while handling section [%zd] %s",
+				     ndx, sname);
+			      goto cleanup;
+			    }
 			  shstrtab_name = xstrdup (sname);
 			  shstrtab_newname = xstrdup (newname);
 			}
@@ -786,6 +795,15 @@ process_file (const char *fname)
 			{
 			  shstrtab_size = size;
 			  shstrtab_compressed = T_COMPRESS_ZLIB;
+			  if (shstrtab_name != NULL
+			      || shstrtab_newname != NULL)
+			    {
+			      error (0, 0, "Internal error,"
+					   " shstrtab_name already set,"
+					   " while handling section [%zd] %s",
+				     ndx, sname);
+			      goto cleanup;
+			    }
 			  shstrtab_name = xstrdup (sname);
 			  shstrtab_newname = (newname == NULL
 					      ? NULL : xstrdup (newname));
@@ -919,6 +937,12 @@ process_file (const char *fname)
 		}
 	      size_t elsize = gelf_fsize (elfnew, ELF_T_SYM, 1, EV_CURRENT);
 	      size_t syms = symd->d_size / elsize;
+	      if (symstrents != NULL)
+		{
+		  error (0, 0, "Internal error, symstrents already set,"
+			 " while handling section [%zd] %s", ndx, name);
+		  goto cleanup;
+		}
 	      symstrents = xmalloc (syms * sizeof (Dwelf_Strent *));
 	      for (size_t i = 0; i < syms; i++)
 		{
-- 
2.18.4


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

* Re: [PATCH] elfcompress: Add sanity checks to make sure to not override variable
  2022-05-10 10:35 [PATCH] elfcompress: Add sanity checks to make sure to not override variable Mark Wielaard
@ 2022-05-14 13:14 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2022-05-14 13:14 UTC (permalink / raw)
  To: elfutils-devel

Hi,

On Tue, May 10, 2022 at 12:35:01PM +0200, Mark Wielaard wrote:
> The process_file code is a little tricky. Add sanity checks to make
> sure shstrtab_name, shstrtab_newname and symstrents are only set once.

Pushed.

Cheers,

Mark

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

end of thread, other threads:[~2022-05-14 13:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 10:35 [PATCH] elfcompress: Add sanity checks to make sure to not override variable Mark Wielaard
2022-05-14 13:14 ` 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).