Blame SOURCES/elfutils-0.188-compile-warnings.patch

ea5461
commit 75f2de448f311807e2493f2a37a980e2d872b229
ea5461
Author: Mark Wielaard <mark@klomp.org>
ea5461
Date:   Thu Nov 3 13:38:45 2022 +0100
ea5461
ea5461
    readelf: Check phdr != NULL or shdr != NULL in handle_dynamic.
ea5461
    
ea5461
    The compiler doesn't know that when use_dynamic_segment is true,
ea5461
    then phdr should/will be non-NULL and otherwise shdr is non-NULL.
ea5461
    Add explicit checks to help the compiler out and in case an error
ea5461
    is made calling the handle_dynamic function.
ea5461
    
ea5461
    Signed-off-by: Mark Wielaard <mark@klomp.org>
ea5461
ea5461
diff --git a/src/readelf.c b/src/readelf.c
ea5461
index 0e0b05c4..e721a209 100644
ea5461
--- a/src/readelf.c
ea5461
+++ b/src/readelf.c
ea5461
@@ -1828,7 +1828,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr)
ea5461
   size_t dyn_ents;
ea5461
 
ea5461
   /* Get the data of the section.  */
ea5461
-  if (use_dynamic_segment)
ea5461
+  if (use_dynamic_segment && phdr != NULL)
ea5461
     data = elf_getdata_rawchunk(ebl->elf, phdr->p_offset,
ea5461
 				phdr->p_filesz, ELF_T_DYN);
ea5461
   else
ea5461
@@ -1840,7 +1840,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr)
ea5461
   /* Get the dynamic section entry number */
ea5461
   dyn_ents = get_dyn_ents (data);
ea5461
 
ea5461
-  if (!use_dynamic_segment)
ea5461
+  if (!use_dynamic_segment && shdr != NULL)
ea5461
     {
ea5461
       /* Get the section header string table index.  */
ea5461
       if (unlikely (elf_getshdrstrndx (ebl->elf, &shstrndx) < 0))
ea5461
@@ -1862,7 +1862,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr)
ea5461
 	      (int) shdr->sh_link,
ea5461
 	      elf_strptr (ebl->elf, shstrndx, glink->sh_name));
ea5461
     }
ea5461
-  else
ea5461
+  else if (phdr != NULL)
ea5461
     {
ea5461
       printf (ngettext ("\
ea5461
 \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 "  Offset: %#08" PRIx64 "\n",
ea5461
@@ -1879,7 +1879,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr)
ea5461
   /* if --use-dynamic option is enabled,
ea5461
      use the string table to get the related library info.  */
ea5461
   Elf_Data *strtab_data = NULL;
ea5461
-  if (use_dynamic_segment)
ea5461
+  if (use_dynamic_segment && phdr != NULL)
ea5461
     {
ea5461
       strtab_data = get_dynscn_strtab(ebl->elf, phdr);
ea5461
       if (strtab_data == NULL)
ea5461
@@ -1903,7 +1903,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr, GElf_Phdr *phdr)
ea5461
 	  || dyn->d_tag == DT_RPATH
ea5461
 	  || dyn->d_tag == DT_RUNPATH)
ea5461
 	{
ea5461
-	  if (! use_dynamic_segment)
ea5461
+	  if (! use_dynamic_segment && shdr != NULL)
ea5461
 	    name = elf_strptr (ebl->elf, shdr->sh_link, dyn->d_un.d_val);
ea5461
 	  else if (dyn->d_un.d_val < strtab_data->d_size
ea5461
 		   && memrchr (strtab_data->d_buf + dyn->d_un.d_val, '\0',
ea5461
ea5461
commit b0a0235771906e3bcd6174c4e3c020b5522b0be5
ea5461
Author: Mark Wielaard <mark@klomp.org>
ea5461
Date:   Thu Nov 3 13:44:35 2022 +0100
ea5461
ea5461
    libdw: Don't dereference and assign values we are skipping
ea5461
    
ea5461
    We don't use the FDE address encoding byte, so no reason
ea5461
    to read and store it. Just skip past it.
ea5461
    
ea5461
    Signed-off-by: Mark Wielaard <mark@klomp.org>
ea5461
ea5461
diff --git a/libdw/dwarf_next_cfi.c b/libdw/dwarf_next_cfi.c
ea5461
index 23b16885..be08984f 100644
ea5461
--- a/libdw/dwarf_next_cfi.c
ea5461
+++ b/libdw/dwarf_next_cfi.c
ea5461
@@ -226,7 +226,7 @@ dwarf_next_cfi (const unsigned char e_ident[],
ea5461
 	      if (sized_augmentation)
ea5461
 		{
ea5461
 		  /* Skip FDE address encoding byte.  */
ea5461
-		  encoding = *bytes++;
ea5461
+		  bytes++;
ea5461
 		  continue;
ea5461
 		}
ea5461
 	      break;
ea5461
ea5461
commit 52a6a3110e019d696284fdd822c2a2f0987dded2
ea5461
Author: Mark Wielaard <mark@klomp.org>
ea5461
Date:   Thu Nov 3 13:52:32 2022 +0100
ea5461
ea5461
    readelf: Check gelf_getdyn doesn't return NULL
ea5461
    
ea5461
    Signed-off-by: Mark Wielaard <mark@klomp.org>
ea5461
ea5461
diff --git a/src/readelf.c b/src/readelf.c
ea5461
index e721a209..3dafb041 100644
ea5461
--- a/src/readelf.c
ea5461
+++ b/src/readelf.c
ea5461
@@ -4910,7 +4910,7 @@ get_dynscn_addrs(Elf *elf, GElf_Phdr *phdr, GElf_Addr addrs[i_max])
ea5461
     GElf_Dyn dyn_mem;
ea5461
     GElf_Dyn *dyn = gelf_getdyn(data, dyn_idx, &dyn_mem);
ea5461
     /* DT_NULL Marks end of dynamic section.  */
ea5461
-    if (dyn->d_tag == DT_NULL)
ea5461
+    if (dyn == NULL || dyn->d_tag == DT_NULL)
ea5461
       break;
ea5461
 
ea5461
     switch (dyn->d_tag) {