1 |
commit: 248f21bc40c850b470b6128de00a3437587f9293 |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Jan 24 02:42:41 2017 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Jan 24 02:42:41 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=248f21bc |
7 |
|
8 |
scanelf: switch all string table lookups to scanelf_file_get_symtabs |
9 |
|
10 |
We don't care about the .strtab-vs-.dynstr, but we do want to fall |
11 |
back to tables that can only be found via dynamic tags and program |
12 |
headers. |
13 |
|
14 |
scanelf.c | 46 +++++++++++++++++++++++----------------------- |
15 |
1 file changed, 23 insertions(+), 23 deletions(-) |
16 |
|
17 |
diff --git a/scanelf.c b/scanelf.c |
18 |
index ceec26d..9695276 100644 |
19 |
--- a/scanelf.c |
20 |
+++ b/scanelf.c |
21 |
@@ -767,16 +767,16 @@ static void rpath_security_checks(elfobj *elf, char *item, const char *dt_type) |
22 |
static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len) |
23 |
{ |
24 |
char *rpath, *runpath, **r; |
25 |
- void *strtbl_void; |
26 |
+ void *symtab_void, *strtab_void; |
27 |
|
28 |
if (!show_rpath) return; |
29 |
|
30 |
- strtbl_void = elf_findsecbyname(elf, ".dynstr"); |
31 |
+ scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); |
32 |
rpath = runpath = NULL; |
33 |
|
34 |
#define SHOW_RPATH(B) \ |
35 |
Elf ## B ## _Dyn *dyn; \ |
36 |
- Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ |
37 |
+ Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ |
38 |
Elf ## B ## _Off offset; \ |
39 |
Elf ## B ## _Xword word; \ |
40 |
\ |
41 |
@@ -791,7 +791,7 @@ static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_ |
42 |
continue; \ |
43 |
} \ |
44 |
/* Verify the memory is somewhat sane */ \ |
45 |
- offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
46 |
+ offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
47 |
if (offset < (Elf ## B ## _Off)elf->len) { \ |
48 |
if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \ |
49 |
*r = elf->data + offset; \ |
50 |
@@ -873,7 +873,7 @@ static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_ |
51 |
} \ |
52 |
} \ |
53 |
} |
54 |
- if (elf->phdr && strtbl_void) |
55 |
+ if (elf->phdr && strtab_void) |
56 |
SCANELF_ELF_SIZED(SHOW_RPATH); |
57 |
|
58 |
if (be_wewy_wewy_quiet) return; |
59 |
@@ -913,7 +913,7 @@ static char *lookup_config_lib(const char *fname) |
60 |
static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len) |
61 |
{ |
62 |
char *needed; |
63 |
- void *strtbl_void; |
64 |
+ void *symtab_void, *strtab_void; |
65 |
char *p; |
66 |
|
67 |
/* |
68 |
@@ -923,17 +923,17 @@ static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char |
69 |
if ((op == 0 && !show_needed) || (op == 1 && !find_lib)) |
70 |
return NULL; |
71 |
|
72 |
- strtbl_void = elf_findsecbyname(elf, ".dynstr"); |
73 |
+ scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); |
74 |
|
75 |
#define SHOW_NEEDED(B) \ |
76 |
Elf ## B ## _Dyn *dyn; \ |
77 |
- Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ |
78 |
+ Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ |
79 |
size_t matched = 0; \ |
80 |
\ |
81 |
/* Walk all the dynamic tags to find NEEDED entries */ \ |
82 |
scanelf_dt_for_each(B, elf, dyn) { \ |
83 |
if (EGET(dyn->d_tag) == DT_NEEDED) { \ |
84 |
- Elf ## B ## _Off offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
85 |
+ Elf ## B ## _Off offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
86 |
if (offset >= (Elf ## B ## _Off)elf->len) \ |
87 |
continue; \ |
88 |
needed = elf->data + offset; \ |
89 |
@@ -971,7 +971,7 @@ static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char |
90 |
} \ |
91 |
} \ |
92 |
} |
93 |
- if (elf->phdr && strtbl_void) { |
94 |
+ if (elf->phdr && strtab_void) { |
95 |
SCANELF_ELF_SIZED(SHOW_NEEDED); |
96 |
if (op == 0 && !*found_needed && be_verbose) |
97 |
warn("ELF lacks DT_NEEDED sections: %s", elf->filename); |
98 |
@@ -987,7 +987,7 @@ static char *scanelf_file_interp(elfobj *elf, char *found_interp) |
99 |
|
100 |
if (elf->phdr) { |
101 |
/* Walk all the program headers to find the PT_INTERP */ |
102 |
-#define SHOW_PT_INTERP(B) \ |
103 |
+#define GET_PT_INTERP(B) \ |
104 |
size_t i; \ |
105 |
Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ |
106 |
Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ |
107 |
@@ -997,16 +997,16 @@ static char *scanelf_file_interp(elfobj *elf, char *found_interp) |
108 |
break; \ |
109 |
} \ |
110 |
} |
111 |
- SCANELF_ELF_SIZED(SHOW_PT_INTERP); |
112 |
+ SCANELF_ELF_SIZED(GET_PT_INTERP); |
113 |
} else if (elf->shdr) { |
114 |
/* Use the section headers to find it */ |
115 |
- void *strtbl_void = elf_findsecbyname(elf, ".interp"); |
116 |
+ void *section = elf_findsecbyname(elf, ".interp"); |
117 |
|
118 |
-#define SHOW_INTERP(B) \ |
119 |
- Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ |
120 |
- offset = EGET(strtbl->sh_offset); |
121 |
- if (strtbl_void) |
122 |
- SCANELF_ELF_SIZED(SHOW_INTERP); |
123 |
+#define GET_INTERP(B) \ |
124 |
+ Elf ## B ## _Shdr *shdr = SHDR ## B (section); \ |
125 |
+ offset = EGET(shdr->sh_offset); |
126 |
+ if (section) |
127 |
+ SCANELF_ELF_SIZED(GET_INTERP); |
128 |
} |
129 |
|
130 |
/* Validate the pointer even if we don't use it in output */ |
131 |
@@ -1059,16 +1059,16 @@ static const char *scanelf_file_bind(elfobj *elf, char *found_bind) |
132 |
static char *scanelf_file_soname(elfobj *elf, char *found_soname) |
133 |
{ |
134 |
char *soname; |
135 |
- void *strtbl_void; |
136 |
+ void *symtab_void, *strtab_void; |
137 |
|
138 |
if (!show_soname) return NULL; |
139 |
|
140 |
- strtbl_void = elf_findsecbyname(elf, ".dynstr"); |
141 |
+ scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); |
142 |
|
143 |
#define SHOW_SONAME(B) \ |
144 |
Elf ## B ## _Dyn *dyn; \ |
145 |
Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ |
146 |
- Elf ## B ## _Shdr *strtbl = SHDR ## B (strtbl_void); \ |
147 |
+ Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ |
148 |
\ |
149 |
/* only look for soname in shared objects */ \ |
150 |
if (EGET(ehdr->e_type) != ET_DYN) \ |
151 |
@@ -1076,7 +1076,7 @@ static char *scanelf_file_soname(elfobj *elf, char *found_soname) |
152 |
\ |
153 |
scanelf_dt_for_each(B, elf, dyn) { \ |
154 |
if (EGET(dyn->d_tag) == DT_SONAME) { \ |
155 |
- Elf ## B ## _Off offset = EGET(strtbl->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
156 |
+ Elf ## B ## _Off offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ |
157 |
if (offset >= (Elf ## B ## _Off)elf->len) \ |
158 |
continue; \ |
159 |
soname = elf->data + offset; \ |
160 |
@@ -1084,7 +1084,7 @@ static char *scanelf_file_soname(elfobj *elf, char *found_soname) |
161 |
return (be_wewy_wewy_quiet ? NULL : soname); \ |
162 |
} \ |
163 |
} |
164 |
- if (elf->phdr && strtbl_void) |
165 |
+ if (elf->phdr && strtab_void) |
166 |
SCANELF_ELF_SIZED(SHOW_SONAME); |
167 |
|
168 |
return NULL; |