Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37412054
en ru br
ALT Linux repos
S:0.189.0.46.27a8-alt1
5.0: 0.137-alt2
4.1: 0.131-alt1
4.0: 0.126-alt1
3.0: 0.108-alt3
+backports:0.115-alt0.M30.1

Other repositories
Upstream:0.131

Group :: Development/C
RPM: elfutils

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

Patch: elfutils-0.147-alt-findtextrel.patch
Download


--- elfutils/src/findtextrel.c
+++ elfutils/src/findtextrel.c
@@ -29,7 +29,6 @@
 #endif
 
 #include <argp.h>
-#include <assert.h>
 #include <errno.h>
 #include <error.h>
 #include <fcntl.h>
@@ -489,6 +488,22 @@ ptrcompare (const void *p1, const void *p2)
 }
 
 
+static const char *
+get_idx_str (Elf *elf, Elf_Data *symdata, GElf_Shdr *shdr, GElf_Sym *sym,
+	     int idx)
+{
+  if (idx == -1)
+    return NULL;
+
+  sym = gelf_getsym (symdata, idx, sym);
+  if (!sym)
+    return NULL;
+
+  const char *str = elf_strptr (elf, shdr->sh_link, sym->st_name);
+  return (str && *str) ? str : NULL;
+}
+
+
 static void
 check_rel (size_t nsegments, struct segments segments[nsegments],
 	   GElf_Addr addr, Elf *elf, Elf_Scn *symscn, Dwarf *dw,
@@ -554,15 +569,11 @@ check_rel (size_t nsegments, struct segments segments[nsegments],
 		      }
 		  }
 
-		if (lowidx != -1)
+		const char *lowstr = get_idx_str (elf, symdata, shdr, &sym_mem,
+						  lowidx);
+		if (lowstr)
 		  {
-		    sym = gelf_getsym (symdata, lowidx, &sym_mem);
-		    assert (sym != NULL);
-
-		    const char *lowstr = elf_strptr (elf, shdr->sh_link,
-						     sym->st_name);
-
-		    if (sym->st_value + sym->st_size > addr)
+		    if (sym_mem.st_value + sym_mem.st_size > addr)
 		      {
 			/* It is this function.  */
 			if (tfind (lowstr, knownsrcs, ptrcompare) == NULL)
@@ -572,31 +583,29 @@ the file containing the function '%s' is not compiled with -fpic/-fPIC\n"),
 				    lowstr);
 			    tsearch (lowstr, knownsrcs, ptrcompare);
 			  }
+			return;
 		      }
-		    else if (highidx == -1)
+		    const char *highstr = get_idx_str (elf, symdata, shdr,
+						       &sym_mem, highidx);
+		    if (!highstr)
 		      printf (gettext ("\
 the file containing the function '%s' might not be compiled with -fpic/-fPIC\n"),
 			      lowstr);
 		    else
 		      {
-			sym = gelf_getsym (symdata, highidx, &sym_mem);
-			assert (sym != NULL);
-
 			printf (gettext ("\
 either the file containing the function '%s' or the file containing the function '%s' is not compiled with -fpic/-fPIC\n"),
-				lowstr, elf_strptr (elf, shdr->sh_link,
-						    sym->st_name));
+				lowstr, highstr);
 		      }
 		    return;
 		  }
-		else if (highidx != -1)
+		const char *highstr = get_idx_str (elf, symdata, shdr,
+						   &sym_mem, highidx);
+		if (highstr)
 		  {
-		    sym = gelf_getsym (symdata, highidx, &sym_mem);
-		    assert (sym != NULL);
-
 		    printf (gettext ("\
 the file containing the function '%s' might not be compiled with -fpic/-fPIC\n"),
-			    elf_strptr (elf, shdr->sh_link, sym->st_name));
+			    highstr);
 		    return;
 		  }
 	      }
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin