]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcompress: Add sanity checks to make sure to not override variable
authorMark Wielaard <mark@klomp.org>
Tue, 10 May 2022 10:31:04 +0000 (12:31 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 14 May 2022 13:08:47 +0000 (15:08 +0200)
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
src/elfcompress.c

index fd87ce2f54192a05a87e6d6eb16d1a9b026b3bcd..ae09eb1f30b54fe7192cb59f1865423b87fc3257 100644 (file)
@@ -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-04-24  Mark Wielaard  <mark@klomp.org>
 
        * elfclassify.c (main): Use classify_flag_no_stdin for no-std in options.
index 92f2fac8e0d93ffa885eec53f46a49004bb0b867..6f18e47d12125d2c49dc48ad5e78cd2e13ab6207 100644 (file)
@@ -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++)
                {