]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use the empty string for note names with zero size (without any data).
authorMark Wielaard <mark@klomp.org>
Fri, 24 Mar 2017 13:10:26 +0000 (14:10 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 3 Apr 2017 21:47:59 +0000 (23:47 +0200)
ELF notes can have a zero sized name. In which case there is no data at
all (so also no zero terminator). Make sure to use the empty string for
such notes if the code does not otherwise explicitly check n_namesz.

https://sourceware.org/bugzilla/show_bug.cgi?id=21300

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/linux-core-attach.c
src/ChangeLog
src/elfcmp.c
src/readelf.c

index 4c9f4f6acb3d780bb2e8c1488470b7b9b86beedf..ede6d47100133f2abd91cfeab7bceb18ea806cf8 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-24  Mark Wielaard  <mark@klomp.org>
+
+       * linux-core-attach.c (core_next_thread): If n_namesz == 0 then
+       the note name data is the empty string.
+       (dwfl_core_file_attach): Likewise.
+
 2017-02-15  Ulf Hermann  <ulf.hermann@qt.io>
 
        * linux-kernel-modules.c: Include system.h.
index 93d0e46eb49d1db38eed0b2ab1021d818003f34b..f82ed03219952059ef70b24c1df01bd18b8640a6 100644 (file)
@@ -125,7 +125,8 @@ core_next_thread (Dwfl *dwfl __attribute__ ((unused)), void *dwfl_arg,
                                                          &desc_offset)) > 0)
     {
       /* Do not check NAME for now, help broken Linux kernels.  */
-      const char *name = note_data->d_buf + name_offset;
+      const char *name = (nhdr.n_namesz == 0
+                         ? "" : note_data->d_buf + name_offset);
       const char *desc = note_data->d_buf + desc_offset;
       GElf_Word regs_offset;
       size_t nregloc;
@@ -178,7 +179,8 @@ core_set_initial_registers (Dwfl_Thread *thread, void *thread_arg_voidp)
   /* __libdwfl_attach_state_for_core already verified the note is there.  */
   assert (getnote_err != 0);
   /* Do not check NAME for now, help broken Linux kernels.  */
-  const char *name = note_data->d_buf + name_offset;
+  const char *name = (nhdr.n_namesz == 0
+                     ? "" : note_data->d_buf + name_offset);
   const char *desc = note_data->d_buf + desc_offset;
   GElf_Word regs_offset;
   size_t nregloc;
@@ -367,7 +369,8 @@ dwfl_core_file_attach (Dwfl *dwfl, Elf *core)
                                    &nhdr, &name_offset, &desc_offset)) > 0)
     {
       /* Do not check NAME for now, help broken Linux kernels.  */
-      const char *name = note_data->d_buf + name_offset;
+      const char *name = (nhdr.n_namesz == 0
+                         ? "" : note_data->d_buf + name_offset);
       const char *desc = note_data->d_buf + desc_offset;
       GElf_Word regs_offset;
       size_t nregloc;
index 9dd76c00a592e86654abfe69885dc7ccbc081d5f..41381aa03b3564a5c3efa49e216b94c98e82b955 100644 (file)
@@ -1,3 +1,9 @@
+2017-03-24  Mark Wielaard  <mjw@redhat.com>
+
+       * elfcmp.c (main): If n_namesz == 0 then the note name data is the
+       empty string.
+       * readelf.c (handle_notes_data): Likewise.
+
 2017-03-24  Mark Wielaard  <mjw@redhat.com>
 
        * readelf.c (handle_gnu_hash): Check inner < max_nsyms before
index 7673cf212c01788be03aed984e4e4eb577b61c4d..50464207b021d115649ede8006bb754fb5f157f9 100644 (file)
@@ -419,7 +419,8 @@ main (int argc, char *argv[])
                   && (off1 = gelf_getnote (data1, off1, &note1,
                                            &name_offset, &desc_offset)) > 0)
              {
-               const char *name1 = data1->d_buf + name_offset;
+               const char *name1 = (note1.n_namesz == 0
+                                    ? "" : data1->d_buf + name_offset);
                const void *desc1 = data1->d_buf + desc_offset;
                if (off2 >= data2->d_size)
                  {
@@ -435,7 +436,8 @@ main (int argc, char *argv[])
                  error (2, 0, gettext ("\
 cannot read note section [%zu] '%s' in '%s': %s"),
                         elf_ndxscn (scn2), sname2, fname2, elf_errmsg (-1));
-               const char *name2 = data2->d_buf + name_offset;
+               const char *name2 = (note2.n_namesz == 0
+                                    ? "" : data2->d_buf + name_offset);
                const void *desc2 = data2->d_buf + desc_offset;
 
                if (note1.n_namesz != note2.n_namesz
index 490b6d592ebab1c42eb584aa5002007c4e3df6cd..97a43b06659c75b37b85905106e8a7f9bde9f638 100644 (file)
@@ -9365,7 +9365,7 @@ handle_notes_data (Ebl *ebl, const GElf_Ehdr *ehdr,
         && (offset = gelf_getnote (data, offset,
                                    &nhdr, &name_offset, &desc_offset)) > 0)
     {
-      const char *name = data->d_buf + name_offset;
+      const char *name = nhdr.n_namesz == 0 ? "" : data->d_buf + name_offset;
       const char *desc = data->d_buf + desc_offset;
 
       char buf[100];