1 |
flameeyes 07/12/30 18:59:51 |
2 |
|
3 |
Added: elfutils-0.118-PaX-support.patch |
4 |
elfutils-0.118-libelf-link.patch |
5 |
elfutils-portability.patch elfutils-robustify.patch |
6 |
elfutils-strip-copy-symtab.patch |
7 |
Log: |
8 |
Update patches for elfutils-0.131. |
9 |
|
10 |
Revision Changes Path |
11 |
1.1 src/patchsets/elfutils/0.131/elfutils-0.118-PaX-support.patch |
12 |
|
13 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-0.118-PaX-support.patch?rev=1.1&view=markup |
14 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-0.118-PaX-support.patch?rev=1.1&content-type=text/plain |
15 |
|
16 |
Index: elfutils-0.118-PaX-support.patch |
17 |
=================================================================== |
18 |
Add support for PaX ELF markings |
19 |
|
20 |
Patch by Kevin F. Quinn <kevquinn@g.o> |
21 |
|
22 |
http://bugs.gentoo.org/115100 |
23 |
|
24 |
--- libelf/elf.h |
25 |
+++ libelf/elf.h |
26 |
@@ -568,6 +568,7 @@ |
27 |
#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */ |
28 |
#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */ |
29 |
#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */ |
30 |
+#define PT_PAX_FLAGS 0x65041580 /* Indicates PaX flag markings */ |
31 |
#define PT_LOSUNW 0x6ffffffa |
32 |
#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */ |
33 |
#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */ |
34 |
--- src/elflint.c |
35 |
+++ src/elflint.c |
36 |
@@ -3187,6 +3187,7 @@ |
37 |
|
38 |
if (phdr->p_type >= PT_NUM && phdr->p_type != PT_GNU_EH_FRAME |
39 |
&& phdr->p_type != PT_GNU_STACK && phdr->p_type != PT_GNU_RELRO |
40 |
+ && phdr->p_type != PT_PAX_FLAGS |
41 |
/* Check for a known machine-specific type. */ |
42 |
&& ebl_segment_type_name (ebl, phdr->p_type, NULL, 0) == NULL) |
43 |
ERROR (gettext ("\ |
44 |
|
45 |
|
46 |
|
47 |
1.1 src/patchsets/elfutils/0.131/elfutils-0.118-libelf-link.patch |
48 |
|
49 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-0.118-libelf-link.patch?rev=1.1&view=markup |
50 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-0.118-libelf-link.patch?rev=1.1&content-type=text/plain |
51 |
|
52 |
Index: elfutils-0.118-libelf-link.patch |
53 |
=================================================================== |
54 |
libdw needs libelf |
55 |
|
56 |
http://bugs.gentoo.org/115385 |
57 |
|
58 |
--- src/Makefile.am |
59 |
+++ src/Makefile.am |
60 |
@@ -93,7 +93,7 @@ |
61 |
ld_LDFLAGS = -rdynamic |
62 |
elflint_LDADD = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl |
63 |
findtextrel_LDADD = $(libdw) $(libelf) $(libmudflap) |
64 |
-addr2line_LDADD = $(libdw) $(libmudflap) |
65 |
+addr2line_LDADD = $(libdw) $(libelf) $(libmudflap) |
66 |
elfcmp_LDADD = $(libebl) $(libelf) $(libmudflap) -ldl |
67 |
objdump_LDADD = $(libebl) $(libelf) $(libeu) $(libmudflap) -ldl |
68 |
ranlib_LDADD = $(libelf) $(libeu) $(libmudflap) |
69 |
--- tests/Makefile.am |
70 |
+++ tests/Makefile.am |
71 |
@@ -160,12 +160,12 @@ |
72 |
get_aranges_LDADD = $(libdw) $(libelf) $(libmudflap) |
73 |
allfcts_LDADD = $(libdw) $(libelf) $(libmudflap) |
74 |
line2addr_no_Wformat = yes |
75 |
-line2addr_LDADD = $(libdw) $(libmudflap) |
76 |
-addrscopes_LDADD = $(libdw) $(libmudflap) |
77 |
-funcscopes_LDADD = $(libdw) $(libmudflap) |
78 |
-funcretval_LDADD = $(libdw) $(libmudflap) |
79 |
-allregs_LDADD = $(libdw) $(libmudflap) |
80 |
-find_prologues_LDADD = $(libdw) $(libmudflap) |
81 |
+line2addr_LDADD = $(libdw) $(libelf) $(libmudflap) |
82 |
+addrscopes_LDADD = $(libdw) $(libelf) $(libmudflap) |
83 |
+funcscopes_LDADD = $(libdw) $(libelf) $(libmudflap) |
84 |
+funcretval_LDADD = $(libdw) $(libelf) $(libmudflap) |
85 |
+allregs_LDADD = $(libdw) $(libelf) $(libmudflap) |
86 |
+find_prologues_LDADD = $(libdw) $(libelf) $(libmudflap) |
87 |
#show_ciefde_LDADD = ../libdwarf/libdwarf.so $(libelf) $(libmudflap) |
88 |
asm_tst1_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl |
89 |
asm_tst2_LDADD = $(libasm) $(libebl) $(libelf) $(libmudflap) -ldl |
90 |
|
91 |
|
92 |
|
93 |
1.1 src/patchsets/elfutils/0.131/elfutils-portability.patch |
94 |
|
95 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-portability.patch?rev=1.1&view=markup |
96 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-portability.patch?rev=1.1&content-type=text/plain |
97 |
|
98 |
Index: elfutils-portability.patch |
99 |
=================================================================== |
100 |
--- elfutils/backends/ChangeLog |
101 |
+++ elfutils/backends/ChangeLog |
102 |
@@ -135,6 +135,11 @@ |
103 |
* sparc_init.c: Likewise. |
104 |
* x86_64_init.c: Likewise. |
105 |
|
106 |
+2005-11-22 Roland McGrath <roland@××××××.com> |
107 |
+ |
108 |
+ * Makefile.am (LD_AS_NEEDED): New variable, substituted by configure. |
109 |
+ (libebl_%.so rule): Use it in place of -Wl,--as-needed. |
110 |
+ |
111 |
2005-11-19 Roland McGrath <roland@××××××.com> |
112 |
|
113 |
* ppc64_reloc.def: REL30 -> ADDR30. |
114 |
@@ -157,6 +162,9 @@ |
115 |
* Makefile.am (uninstall): Don't try to remove $(pkgincludedir). |
116 |
(CLEANFILES): Add libebl_$(m).so. |
117 |
|
118 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
119 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
120 |
+ |
121 |
* ppc_reloc.def: Update bits per Alan Modra <amodra@×××××××××××.au>. |
122 |
* ppc64_reloc.def: Likewise. |
123 |
|
124 |
--- elfutils/backends/Makefile.am |
125 |
+++ elfutils/backends/Makefile.am |
126 |
@@ -25,12 +25,14 @@ |
127 |
## <http://www.openinventionnetwork.com>. |
128 |
## |
129 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DOBJDIR=\"$(shell pwd)\" |
130 |
+WEXTRA = @WEXTRA@ |
131 |
+LD_AS_NEEDED = @LD_AS_NEEDED@ |
132 |
if MUDFLAP |
133 |
AM_CFLAGS = -fmudflap |
134 |
else |
135 |
AM_CFLAGS = |
136 |
endif |
137 |
-AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 \ |
138 |
+AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused $(WEXTRA) -Wformat=2 \ |
139 |
-std=gnu99 |
140 |
INCLUDES = -I$(srcdir) -I$(top_srcdir)/libebl \ |
141 |
-I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ |
142 |
@@ -62,7 +64,7 @@ textrel_check = if readelf -d $@ | fgrep |
143 |
libebl_%.so: libebl_%_pic.a libebl_%.map $(libelf) $(libdw) |
144 |
$(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ |
145 |
-Wl,--version-script,$(word 2,$^) \ |
146 |
- -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libmudflap) |
147 |
+ -Wl,-z,defs $(LD_AS_NEEDED) $(libelf) $(libdw) $(libmudflap) |
148 |
$(textrel_check) |
149 |
|
150 |
libebl_%.map: Makefile |
151 |
--- elfutils/ChangeLog |
152 |
+++ elfutils/ChangeLog |
153 |
@@ -15,6 +15,10 @@ |
154 |
* configure.ac: Add dummy automake conditional to get dependencies |
155 |
for non-generic linker right. See src/Makefile.am. |
156 |
|
157 |
+2005-11-22 Roland McGrath <roland@××××××.com> |
158 |
+ |
159 |
+ * configure.ac: Check for --as-needed linker option. |
160 |
+ |
161 |
2005-11-18 Roland McGrath <roland@××××××.com> |
162 |
|
163 |
* Makefile.am (DISTCHECK_CONFIGURE_FLAGS): New variable. |
164 |
@@ -62,6 +66,17 @@ |
165 |
* Makefile.am (all_SUBDIRS): Add libdwfl. |
166 |
* configure.ac: Write libdwfl/Makefile. |
167 |
|
168 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
169 |
+ |
170 |
+ * configure.ac (WEXTRA): Check for -Wextra and set this substitution. |
171 |
+ |
172 |
+ * configure.ac: Check for struct stat st_?tim members. |
173 |
+ * src/strip.c (process_file): Use st_?time if st_?tim are not there. |
174 |
+ |
175 |
+ * configure.ac: Check for futimes function. |
176 |
+ * src/strip.c (handle_elf) [! HAVE_FUTIMES]: Use utimes instead. |
177 |
+ (handle_ar) [! HAVE_FUTIMES]: Likewise. |
178 |
+ |
179 |
2005-05-19 Roland McGrath <roland@××××××.com> |
180 |
|
181 |
* configure.ac [AH_BOTTOM] (INTDECL, _INTDECL): New macros. |
182 |
--- elfutils/configure.ac |
183 |
+++ elfutils/configure.ac |
184 |
@@ -70,6 +70,34 @@ CFLAGS="$old_CFLAGS"]) |
185 |
AS_IF([test "x$ac_cv_c99" != xyes], |
186 |
AC_MSG_ERROR([gcc with C99 support required])) |
187 |
|
188 |
+AC_CACHE_CHECK([for -Wextra option to $CC], ac_cv_cc_wextra, [dnl |
189 |
+old_CFLAGS="$CFLAGS" |
190 |
+CFLAGS="$CFLAGS -Wextra" |
191 |
+AC_COMPILE_IFELSE([void foo (void) { }], |
192 |
+ ac_cv_cc_wextra=yes, ac_cv_cc_wextra=no) |
193 |
+CFLAGS="$old_CFLAGS"]) |
194 |
+AC_SUBST(WEXTRA) |
195 |
+AS_IF([test "x$ac_cv_cc_wextra" = xyes], [WEXTRA=-Wextra], [WEXTRA=-W]) |
196 |
+ |
197 |
+AC_CACHE_CHECK([for --as-needed linker option], |
198 |
+ ac_cv_as_needed, [dnl |
199 |
+cat > conftest.c <<EOF |
200 |
+int main (void) { return 0; } |
201 |
+EOF |
202 |
+if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS |
203 |
+ -fPIC -shared -o conftest.so conftest.c |
204 |
+ -Wl,--as-needed 1>&AS_MESSAGE_LOG_FD]) |
205 |
+then |
206 |
+ ac_cv_as_needed=yes |
207 |
+else |
208 |
+ ac_cv_as_needed=no |
209 |
+fi |
210 |
+rm -f conftest*]) |
211 |
+AS_IF([test "x$ac_cv_as_needed" = xyes], |
212 |
+ [LD_AS_NEEDED=-Wl,--as-needed], [LD_AS_NEEDED=]) |
213 |
+AC_SUBST(LD_AS_NEEDED) |
214 |
+ |
215 |
+ |
216 |
LOCALEDIR=$datadir |
217 |
AC_SUBST(LOCALEDIR) |
218 |
AC_DEFINE_UNQUOTED(LOCALEDIR, "$LOCALEDIR") |
219 |
--- elfutils/lib/ChangeLog |
220 |
+++ elfutils/lib/ChangeLog |
221 |
@@ -16,6 +16,11 @@ |
222 |
* Makefile.am (libeu_a_SOURCES): Add it. |
223 |
* system.h: Declare crc32_file. |
224 |
|
225 |
+2005-02-07 Roland McGrath <roland@××××××.com> |
226 |
+ |
227 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
228 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
229 |
+ |
230 |
2005-04-30 Ulrich Drepper <drepper@××××××.com> |
231 |
|
232 |
* Makefile.am: Use -ffunction-sections for xmalloc.c. |
233 |
--- elfutils/lib/Makefile.am |
234 |
+++ elfutils/lib/Makefile.am |
235 |
@@ -25,12 +25,13 @@ |
236 |
## <http://www.openinventionnetwork.com>. |
237 |
## |
238 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H |
239 |
+WEXTRA = @WEXTRA@ |
240 |
if MUDFLAP |
241 |
AM_CFLAGS = -fmudflap |
242 |
else |
243 |
AM_CFLAGS = |
244 |
endif |
245 |
-AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused -Wextra $($(*F)_CFLAGS) |
246 |
+AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused $(WEXTRA) $($(*F)_CFLAGS) |
247 |
INCLUDES = -I$(srcdir)/../libelf -I.. |
248 |
|
249 |
noinst_LIBRARIES = libeu.a |
250 |
--- elfutils/libasm/ChangeLog |
251 |
+++ elfutils/libasm/ChangeLog |
252 |
@@ -32,6 +32,11 @@ |
253 |
* asm_error.c: Add new error ASM_E_IOERROR. |
254 |
* libasmP.h: Add ASM_E_IOERROR definition. |
255 |
|
256 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
257 |
+ |
258 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
259 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
260 |
+ |
261 |
2005-02-15 Ulrich Drepper <drepper@××××××.com> |
262 |
|
263 |
* Makefile.am (AM_CFLAGS): Add -Wunused -Wextra -Wformat=2. |
264 |
--- elfutils/libasm/Makefile.am |
265 |
+++ elfutils/libasm/Makefile.am |
266 |
@@ -25,12 +25,13 @@ |
267 |
## <http://www.openinventionnetwork.com>. |
268 |
## |
269 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H |
270 |
+WEXTRA = @WEXTRA@ |
271 |
if MUDFLAP |
272 |
AM_CFLAGS = -fmudflap |
273 |
else |
274 |
AM_CFLAGS = |
275 |
endif |
276 |
-AM_CFLAGS += -std=gnu99 -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 |
277 |
+AM_CFLAGS += -std=gnu99 -Wall -Wshadow -Werror -Wunused $(WEXTRA) -Wformat=2 |
278 |
INCLUDES = -I. -I$(srcdir) -I.. \ |
279 |
-I$(top_srcdir)/libelf -I$(top_srcdir)/libebl -I$(top_srcdir)/libdw\ |
280 |
-I$(top_srcdir)/lib |
281 |
--- elfutils/libcpu/ChangeLog |
282 |
+++ elfutils/libcpu/ChangeLog |
283 |
@@ -1,3 +1,8 @@ |
284 |
+2005-04-04 Roland McGrath <roland@××××××.com> |
285 |
+ |
286 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
287 |
+ (AM_CFLAGS): Use it instead of -Wextra. |
288 |
+ |
289 |
2005-02-15 Ulrich Drepper <drepper@××××××.com> |
290 |
|
291 |
* Makefile (AM_CFLAGS): Add -Wunused -Wextra -Wformat=2. |
292 |
--- elfutils/libcpu/Makefile.am |
293 |
+++ elfutils/libcpu/Makefile.am |
294 |
@@ -25,7 +25,8 @@ |
295 |
## <http://www.openinventionnetwork.com>. |
296 |
## |
297 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H |
298 |
-AM_CFLAGS = -Wall -Wshadow -Werror -Wextra -Wformat=2 -Wunused |
299 |
+WEXTRA = @WEXTRA@ |
300 |
+AM_CFLAGS = -Wall -Wshadow -Werror $(WEXTRA) -Wformat=2 -Wunused |
301 |
INCLUDES = -I$(srcdir) |
302 |
|
303 |
noinst_LIBRARIES = libcpu_i386.a |
304 |
--- elfutils/libdw/ChangeLog |
305 |
+++ elfutils/libdw/ChangeLog |
306 |
@@ -370,6 +370,11 @@ |
307 |
|
308 |
2005-05-31 Roland McGrath <roland@××××××.com> |
309 |
|
310 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
311 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
312 |
+ |
313 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
314 |
+ |
315 |
* dwarf_formref_die.c (dwarf_formref_die): Add CU header offset to |
316 |
formref offset. |
317 |
|
318 |
--- elfutils/libdw/Makefile.am |
319 |
+++ elfutils/libdw/Makefile.am |
320 |
@@ -25,6 +25,7 @@ |
321 |
## <http://www.openinventionnetwork.com>. |
322 |
## |
323 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DIS_LIBDW |
324 |
+WEXTRA = @WEXTRA@ |
325 |
if MUDFLAP |
326 |
AM_CFLAGS = -fmudflap |
327 |
else |
328 |
@@ -33,7 +34,7 @@ endif |
329 |
if BUILD_STATIC |
330 |
AM_CFLAGS += -fpic |
331 |
endif |
332 |
-AM_CFLAGS += -Wall -Werror -Wshadow -Wunused -Wformat=2 -Wextra -std=gnu99 |
333 |
+AM_CFLAGS += -Wall -Werror -Wshadow -Wunused -Wformat=2 $(WEXTRA) -std=gnu99 |
334 |
INCLUDES = -I. -I$(srcdir) -I$(srcdir)/../libelf -I.. -I$(srcdir)/../lib |
335 |
VERSION = 1 |
336 |
|
337 |
--- elfutils/libdwfl/ChangeLog |
338 |
+++ elfutils/libdwfl/ChangeLog |
339 |
@@ -474,6 +474,11 @@ |
340 |
|
341 |
2005-07-21 Roland McGrath <roland@××××××.com> |
342 |
|
343 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
344 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
345 |
+ |
346 |
+2005-07-21 Roland McGrath <roland@××××××.com> |
347 |
+ |
348 |
* Makefile.am (noinst_HEADERS): Add loc2c.c. |
349 |
|
350 |
* test2.c (main): Check sscanf result to quiet warning. |
351 |
--- elfutils/libdwfl/Makefile.am |
352 |
+++ elfutils/libdwfl/Makefile.am |
353 |
@@ -27,12 +27,13 @@ |
354 |
## <http://www.openinventionnetwork.com>. |
355 |
## |
356 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H |
357 |
+WEXTRA = @WEXTRA@ |
358 |
if MUDFLAP |
359 |
AM_CFLAGS = -fmudflap |
360 |
else |
361 |
AM_CFLAGS = |
362 |
endif |
363 |
-AM_CFLAGS += -Wall -Werror -Wshadow -Wunused -Wformat=2 -Wextra -std=gnu99 |
364 |
+AM_CFLAGS += -Wall -Werror -Wshadow -Wunused -Wformat=2 $(WEXTRA) -std=gnu99 |
365 |
INCLUDES = -I. -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ |
366 |
-I$(srcdir)/../libdw -I.. -I$(srcdir)/../lib |
367 |
VERSION = 1 |
368 |
--- elfutils/libebl/ChangeLog |
369 |
+++ elfutils/libebl/ChangeLog |
370 |
@@ -465,6 +465,11 @@ |
371 |
* Makefile.am (libebl_*_so_SOURCES): Set to $(*_SRCS) so dependency |
372 |
tracking works right. |
373 |
|
374 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
375 |
+ |
376 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
377 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
378 |
+ |
379 |
2005-05-21 Ulrich Drepper <drepper@××××××.com> |
380 |
|
381 |
* libebl_x86_64.map: Add x86_64_core_note. |
382 |
--- elfutils/libebl/Makefile.am |
383 |
+++ elfutils/libebl/Makefile.am |
384 |
@@ -25,12 +25,13 @@ |
385 |
## <http://www.openinventionnetwork.com>. |
386 |
## |
387 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DOBJDIR=\"$(shell pwd)\" |
388 |
+WEXTRA = @WEXTRA@ |
389 |
if MUDFLAP |
390 |
AM_CFLAGS = -fmudflap |
391 |
else |
392 |
AM_CFLAGS = |
393 |
endif |
394 |
-AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 \ |
395 |
+AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused $(WEXTRA) -Wformat=2 \ |
396 |
-std=gnu99 |
397 |
|
398 |
INCLUDES = -I$(srcdir) -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ |
399 |
--- elfutils/libelf/ChangeLog |
400 |
+++ elfutils/libelf/ChangeLog |
401 |
@@ -221,6 +221,11 @@ |
402 |
If section content hasn't been read yet, do it before looking for the |
403 |
block size. If no section data present, infer size of section header. |
404 |
|
405 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
406 |
+ |
407 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
408 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
409 |
+ |
410 |
2005-05-11 Ulrich Drepper <drepper@××××××.com> |
411 |
|
412 |
* elf.h: Update again. |
413 |
--- elfutils/libelf/common.h |
414 |
+++ elfutils/libelf/common.h |
415 |
@@ -155,7 +155,7 @@ libelf_release_all (Elf *elf) |
416 |
(Var) = (sizeof (Var) == 1 \ |
417 |
? (unsigned char) (Var) \ |
418 |
: (sizeof (Var) == 2 \ |
419 |
- ? bswap_16 (Var) \ |
420 |
+ ? (unsigned short int) bswap_16 (Var) \ |
421 |
: (sizeof (Var) == 4 \ |
422 |
? bswap_32 (Var) \ |
423 |
: bswap_64 (Var)))) |
424 |
@@ -164,7 +164,7 @@ libelf_release_all (Elf *elf) |
425 |
(Dst) = (sizeof (Var) == 1 \ |
426 |
? (unsigned char) (Var) \ |
427 |
: (sizeof (Var) == 2 \ |
428 |
- ? bswap_16 (Var) \ |
429 |
+ ? (unsigned short int) bswap_16 (Var) \ |
430 |
: (sizeof (Var) == 4 \ |
431 |
? bswap_32 (Var) \ |
432 |
: bswap_64 (Var)))) |
433 |
--- elfutils/libelf/Makefile.am |
434 |
+++ elfutils/libelf/Makefile.am |
435 |
@@ -25,6 +25,7 @@ |
436 |
## <http://www.openinventionnetwork.com>. |
437 |
## |
438 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H |
439 |
+WEXTRA = @WEXTRA@ |
440 |
if MUDFLAP |
441 |
AM_CFLAGS = -fmudflap |
442 |
else |
443 |
@@ -33,7 +34,10 @@ endif |
444 |
if BUILD_STATIC |
445 |
AM_CFLAGS += -fpic |
446 |
endif |
447 |
-AM_CFLAGS += -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 -std=gnu99 \ |
448 |
+if BUILD_STATIC |
449 |
+AM_CFLAGS += -fpic |
450 |
+endif |
451 |
+AM_CFLAGS += -Wall -Wshadow -Werror -Wunused $(WEXTRA) -Wformat=2 -std=gnu99 \ |
452 |
$($(*F)_CFLAGS) |
453 |
INCLUDES = -I$(srcdir) -I$(top_srcdir)/lib -I.. |
454 |
GCC_INCLUDE = -I$(shell $(CC) -print-file-name=include) |
455 |
--- elfutils/src/ChangeLog |
456 |
+++ elfutils/src/ChangeLog |
457 |
@@ -87,6 +87,10 @@ |
458 |
* elflint.c (valid_e_machine): Add EM_ALPHA. |
459 |
Reported by Christian Aichinger <Greek0@×××.net>. |
460 |
|
461 |
+ * strings.c (map_file): Define POSIX_MADV_SEQUENTIAL to |
462 |
+ MADV_SEQUENTIAL if undefined. Don't call posix_madvise |
463 |
+ if neither is defined. |
464 |
+ |
465 |
2006-08-08 Ulrich Drepper <drepper@××××××.com> |
466 |
|
467 |
* elflint.c (check_dynamic): Don't require DT_HASH for DT_SYMTAB. |
468 |
@@ -163,6 +167,10 @@ |
469 |
* Makefile.am: Add hacks to create dependency files for non-generic |
470 |
linker. |
471 |
|
472 |
+2006-04-05 Roland McGrath <roland@××××××.com> |
473 |
+ |
474 |
+ * strings.c (MAP_POPULATE): Define to 0 if undefined. |
475 |
+ |
476 |
2006-06-12 Ulrich Drepper <drepper@××××××.com> |
477 |
|
478 |
* ldgeneric.c (ld_generic_generate_sections): Don't create .interp |
479 |
@@ -511,6 +519,11 @@ |
480 |
* readelf.c (print_debug_loc_section): Fix indentation for larger |
481 |
address size. |
482 |
|
483 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
484 |
+ |
485 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
486 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
487 |
+ |
488 |
2005-05-30 Roland McGrath <roland@××××××.com> |
489 |
|
490 |
* readelf.c (print_debug_line_section): Print section offset of each |
491 |
--- elfutils/src/findtextrel.c |
492 |
+++ elfutils/src/findtextrel.c |
493 |
@@ -488,7 +488,11 @@ ptrcompare (const void *p1, const void * |
494 |
|
495 |
|
496 |
static void |
497 |
-check_rel (size_t nsegments, struct segments segments[nsegments], |
498 |
+check_rel (size_t nsegments, struct segments segments[ |
499 |
+#if __GNUC__ >= 4 |
500 |
+ nsegments |
501 |
+#endif |
502 |
+ ], |
503 |
GElf_Addr addr, Elf *elf, Elf_Scn *symscn, Dwarf *dw, |
504 |
const char *fname, bool more_than_one, void **knownsrcs) |
505 |
{ |
506 |
--- elfutils/src/Makefile.am |
507 |
+++ elfutils/src/Makefile.am |
508 |
@@ -26,6 +26,7 @@ |
509 |
## |
510 |
DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H $(YYDEBUG) \ |
511 |
-DSRCDIR=\"$(shell cd $(srcdir);pwd)\" -DOBJDIR=\"$(shell pwd)\" |
512 |
+WEXTRA = @WEXTRA@ |
513 |
if MUDFLAP |
514 |
AM_CFLAGS = -fmudflap |
515 |
else |
516 |
@@ -33,7 +34,7 @@ AM_CFLAGS = |
517 |
endif |
518 |
AM_CFLAGS += -Wall -Wshadow -std=gnu99 $(native_ld_cflags) \ |
519 |
$(if $($(*F)_no_Werror),,-Werror) \ |
520 |
- $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \ |
521 |
+ $(if $($(*F)_no_Wunused),,-Wunused $(WEXTRA)) \ |
522 |
$(if $($(*F)_no_Wformat),,-Wformat=2) $(CFLAGS_$(*F)) |
523 |
|
524 |
INCLUDES = -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ |
525 |
--- elfutils/src/strings.c |
526 |
+++ elfutils/src/strings.c |
527 |
@@ -51,6 +51,10 @@ |
528 |
|
529 |
#include <system.h> |
530 |
|
531 |
+#ifndef MAP_POPULATE |
532 |
+# define MAP_POPULATE 0 |
533 |
+#endif |
534 |
+ |
535 |
|
536 |
/* Prototypes of local functions. */ |
537 |
static int read_fd (int fd, const char *fname, off64_t fdlen); |
538 |
@@ -491,8 +495,13 @@ map_file (int fd, off64_t start_off, off |
539 |
fd, start_off); |
540 |
if (mem != MAP_FAILED) |
541 |
{ |
542 |
+#if !defined POSIX_MADV_SEQUENTIAL && defined MADV_SEQUENTIAL |
543 |
+# define POSIX_MADV_SEQUENTIAL MADV_SEQUENTIAL |
544 |
+#endif |
545 |
+#ifdef POSIX_MADV_SEQUENTIAL |
546 |
/* We will go through the mapping sequentially. */ |
547 |
(void) posix_madvise (mem, map_size, POSIX_MADV_SEQUENTIAL); |
548 |
+#endif |
549 |
break; |
550 |
} |
551 |
if (errno != EINVAL && errno != ENOMEM) |
552 |
--- elfutils/src/strip.c |
553 |
+++ elfutils/src/strip.c |
554 |
@@ -52,6 +52,12 @@ |
555 |
#include <libebl.h> |
556 |
#include <system.h> |
557 |
|
558 |
+#ifdef HAVE_FUTIMES |
559 |
+# define FUTIMES(fd, fname, tvp) futimes (fd, tvp) |
560 |
+#else |
561 |
+# define FUTIMES(fd, fname, tvp) utimes (fname, tvp) |
562 |
+#endif |
563 |
+ |
564 |
|
565 |
/* Name and version of program. */ |
566 |
static void print_version (FILE *stream, struct argp_state *state); |
567 |
@@ -300,8 +306,18 @@ process_file (const char *fname) |
568 |
|
569 |
/* If we have to preserve the timestamp, we need it in the |
570 |
format utimes() understands. */ |
571 |
+#ifdef HAVE_STRUCT_STAT_ST_ATIM |
572 |
TIMESPEC_TO_TIMEVAL (&tv[0], &pre_st.st_atim); |
573 |
+#else |
574 |
+ tv[0].tv_sec = pre_st.st_atime; |
575 |
+ tv[0].tv_usec = 0; |
576 |
+#endif |
577 |
+#ifdef HAVE_STRUCT_STAT_ST_MTIM |
578 |
TIMESPEC_TO_TIMEVAL (&tv[1], &pre_st.st_mtim); |
579 |
+#else |
580 |
+ tv[1].tv_sec = pre_st.st_atime; |
581 |
+ tv[1].tv_usec = 0; |
582 |
+#endif |
583 |
} |
584 |
|
585 |
/* Open the file. */ |
586 |
@@ -1691,7 +1707,7 @@ handle_elf (int fd, Elf *elf, const char |
587 |
/* If requested, preserve the timestamp. */ |
588 |
if (tvp != NULL) |
589 |
{ |
590 |
- if (futimes (fd, tvp) != 0) |
591 |
+ if (FUTIMES (fd, output_fname, tvp) != 0) |
592 |
{ |
593 |
error (0, errno, gettext ("\ |
594 |
cannot set access and modification date of '%s'"), |
595 |
@@ -1748,7 +1764,7 @@ handle_ar (int fd, Elf *elf, const char |
596 |
|
597 |
if (tvp != NULL) |
598 |
{ |
599 |
- if (unlikely (futimes (fd, tvp) != 0)) |
600 |
+ if (unlikely (FUTIMES (fd, fname, tvp) != 0)) |
601 |
{ |
602 |
error (0, errno, gettext ("\ |
603 |
cannot set access and modification date of '%s'"), fname); |
604 |
--- elfutils/tests/ChangeLog |
605 |
+++ elfutils/tests/ChangeLog |
606 |
@@ -473,6 +473,11 @@ |
607 |
* Makefile.am (TESTS): Add run-elflint-test.sh. |
608 |
(EXTRA_DIST): Add run-elflint-test.sh and testfile18.bz2. |
609 |
|
610 |
+2005-05-31 Roland McGrath <roland@××××××.com> |
611 |
+ |
612 |
+ * Makefile.am (WEXTRA): New variable, substituted by configure. |
613 |
+ (AM_CFLAGS): Use it in place of -Wextra. |
614 |
+ |
615 |
2005-05-24 Ulrich Drepper <drepper@××××××.com> |
616 |
|
617 |
* get-files.c (main): Use correct format specifier. |
618 |
--- elfutils/tests/Makefile.am |
619 |
+++ elfutils/tests/Makefile.am |
620 |
@@ -25,12 +25,13 @@ |
621 |
## <http://www.openinventionnetwork.com>. |
622 |
## |
623 |
DEFS = -DHAVE_CONFIG_H -D_GNU_SOURCE |
624 |
+WEXTRA = @WEXTRA@ |
625 |
if MUDFLAP |
626 |
-AM_CFLAGS = -Wall -Werror -Wextra -std=gnu99 -fmudflap\ |
627 |
+AM_CFLAGS = -Wall -Werror $(WEXTRA) -std=gnu99 -fmudflap\ |
628 |
$(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) |
629 |
BUILD_RPATH = \$$ORIGIN/../backends |
630 |
else |
631 |
-AM_CFLAGS = -Wall -Werror -Wextra -std=gnu99 \ |
632 |
+AM_CFLAGS = -Wall -Werror $(WEXTRA) -std=gnu99 \ |
633 |
$(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) |
634 |
BUILT_RPATH = \$$ORIGIN/../libasm:\$$ORIGIN/../libdw:\$$ORIGIN/../backends:\$$ORIGIN/../libelf |
635 |
endif |
636 |
|
637 |
|
638 |
|
639 |
1.1 src/patchsets/elfutils/0.131/elfutils-robustify.patch |
640 |
|
641 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-robustify.patch?rev=1.1&view=markup |
642 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-robustify.patch?rev=1.1&content-type=text/plain |
643 |
|
644 |
Index: elfutils-robustify.patch |
645 |
=================================================================== |
646 |
src/ |
647 |
2005-06-09 Roland McGrath <roland@××××××.com> |
648 |
|
649 |
* readelf.c (handle_dynamic, handle_symtab): Check for bogus sh_link. |
650 |
(handle_verneed, handle_verdef, handle_versym, handle_hash): Likewise. |
651 |
(handle_scngrp): Check for bogus sh_info. |
652 |
|
653 |
* strip.c (handle_elf): Check for bogus values in sh_link, sh_info, |
654 |
st_shndx, e_shstrndx, and SHT_GROUP or SHT_SYMTAB_SHNDX data. |
655 |
Don't use assert on input values, instead bail with "illformed" error. |
656 |
|
657 |
2005-05-17 Jakub Jelinek <jakub@××××××.com> |
658 |
|
659 |
libelf/ |
660 |
* elf32_getphdr.c (elfw2(LIBELFBITS,getphdr)): Check if program header |
661 |
table fits into object's bounds. |
662 |
* elf_getshstrndx.c (elf_getshstrndx): Add elf->start_offset to |
663 |
elf->map_address. Check if first section header fits into object's |
664 |
bounds. |
665 |
* elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)): |
666 |
Check if section header table fits into object's bounds. |
667 |
* elf_begin.c (get_shnum): Ensure section headers fits into |
668 |
object's bounds. |
669 |
(file_read_elf): Make sure scncnt is small enough to allocate both |
670 |
ElfXX_Shdr and Elf_Scn array. Make sure section and program header |
671 |
tables fit into object's bounds. Avoid memory leak on failure. |
672 |
|
673 |
src/ |
674 |
* elflint.c (check_hash): Don't check entries beyond end of section. |
675 |
(section_name): Return <invalid> if gelf_getshdr returns NULL. |
676 |
|
677 |
2005-05-14 Jakub Jelinek <jakub@××××××.com> |
678 |
|
679 |
libelf/ |
680 |
* libelfP.h (INVALID_NDX): Define. |
681 |
* gelf_getdyn.c (gelf_getdyn): Use it. Remove ndx < 0 test if any. |
682 |
* gelf_getlib.c (gelf_getlib): Likewise. |
683 |
* gelf_getmove.c (gelf_getmove): Likewise. |
684 |
* gelf_getrel.c (gelf_getrel): Likewise. |
685 |
* gelf_getrela.c (gelf_getrela): Likewise. |
686 |
* gelf_getsym.c (gelf_getsym): Likewise. |
687 |
* gelf_getsyminfo.c (gelf_getsyminfo): Likewise. |
688 |
* gelf_getsymshndx.c (gelf_getsymshndx): Likewise. |
689 |
* gelf_getversym.c (gelf_getversym): Likewise. |
690 |
* gelf_update_dyn.c (gelf_update_dyn): Likewise. |
691 |
* gelf_update_lib.c (gelf_update_lib): Likewise. |
692 |
* gelf_update_move.c (gelf_update_move): Likewise. |
693 |
* gelf_update_rel.c (gelf_update_rel): Likewise. |
694 |
* gelf_update_rela.c (gelf_update_rela): Likewise. |
695 |
* gelf_update_sym.c (gelf_update_sym): Likewise. |
696 |
* gelf_update_syminfo.c (gelf_update_syminfo): Likewise. |
697 |
* gelf_update_symshndx.c (gelf_update_symshndx): Likewise. |
698 |
* gelf_update_versym.c (gelf_update_versym): Likewise. |
699 |
* elf_newscn.c (elf_newscn): Check for overflow. |
700 |
* elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Likewise. |
701 |
(__elfw2(LIBELFBITS,updatefile)): Likewise. |
702 |
* elf_begin.c (file_read_elf): Likewise. |
703 |
* elf32_newphdr.c (elfw2(LIBELFBITS,newphdr)): Likewise. |
704 |
* elf_getarsym.c (elf_getarsym): Likewise. |
705 |
* elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)): Likewise. |
706 |
src/ |
707 |
* elflint.c (section_name): Return "<invalid>" instead of |
708 |
crashing on invalid section name. |
709 |
(check_symtab, is_rel_dyn, check_rela, check_rel, check_dynamic, |
710 |
check_symtab_shndx, check_hash, check_versym): Robustify. |
711 |
|
712 |
--- elfutils-0.127/src/readelf.c.robustify |
713 |
+++ elfutils-0.127/src/readelf.c |
714 |
@@ -958,6 +958,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G |
715 |
Elf32_Word *grpref = (Elf32_Word *) data->d_buf; |
716 |
|
717 |
GElf_Sym sym_mem; |
718 |
+ GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem); |
719 |
+ |
720 |
printf ((grpref[0] & GRP_COMDAT) |
721 |
? ngettext ("\ |
722 |
\nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n", |
723 |
@@ -970,8 +972,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G |
724 |
data->d_size / sizeof (Elf32_Word) - 1), |
725 |
elf_ndxscn (scn), |
726 |
elf_strptr (ebl->elf, shstrndx, shdr->sh_name), |
727 |
- elf_strptr (ebl->elf, symshdr->sh_link, |
728 |
- gelf_getsym (symdata, shdr->sh_info, &sym_mem)->st_name) |
729 |
+ (sym == NULL ? NULL |
730 |
+ : elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)) |
731 |
?: gettext ("<INVALID SYMBOL>"), |
732 |
data->d_size / sizeof (Elf32_Word) - 1); |
733 |
|
734 |
@@ -1122,7 +1124,8 @@ static void |
735 |
handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) |
736 |
{ |
737 |
int class = gelf_getclass (ebl->elf); |
738 |
- GElf_Shdr glink; |
739 |
+ GElf_Shdr glink_mem; |
740 |
+ GElf_Shdr *glink; |
741 |
Elf_Data *data; |
742 |
size_t cnt; |
743 |
size_t shstrndx; |
744 |
@@ -1137,6 +1140,11 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, |
745 |
error (EXIT_FAILURE, 0, |
746 |
gettext ("cannot get section header string table index")); |
747 |
|
748 |
+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); |
749 |
+ if (glink == NULL) |
750 |
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), |
751 |
+ elf_ndxscn (scn)); |
752 |
+ |
753 |
printf (ngettext ("\ |
754 |
\nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", |
755 |
"\ |
756 |
@@ -1146,9 +1154,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, |
757 |
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, |
758 |
shdr->sh_offset, |
759 |
(int) shdr->sh_link, |
760 |
- elf_strptr (ebl->elf, shstrndx, |
761 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
762 |
- &glink)->sh_name)); |
763 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
764 |
fputs_unlocked (gettext (" Type Value\n"), stdout); |
765 |
|
766 |
for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
767 |
@@ -1666,6 +1672,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G |
768 |
error (EXIT_FAILURE, 0, |
769 |
gettext ("cannot get section header string table index")); |
770 |
|
771 |
+ GElf_Shdr glink_mem; |
772 |
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
773 |
+ &glink_mem); |
774 |
+ if (glink == NULL) |
775 |
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), |
776 |
+ elf_ndxscn (scn)); |
777 |
+ |
778 |
/* Now we can compute the number of entries in the section. */ |
779 |
unsigned int nsyms = data->d_size / (class == ELFCLASS32 |
780 |
? sizeof (Elf32_Sym) |
781 |
@@ -1676,15 +1689,12 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G |
782 |
nsyms), |
783 |
(unsigned int) elf_ndxscn (scn), |
784 |
elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms); |
785 |
- GElf_Shdr glink; |
786 |
printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n", |
787 |
" %lu local symbols String table: [%2u] '%s'\n", |
788 |
shdr->sh_info), |
789 |
(unsigned long int) shdr->sh_info, |
790 |
(unsigned int) shdr->sh_link, |
791 |
- elf_strptr (ebl->elf, shstrndx, |
792 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
793 |
- &glink)->sh_name)); |
794 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
795 |
|
796 |
fputs_unlocked (class == ELFCLASS32 |
797 |
? gettext ("\ |
798 |
@@ -1920,7 +1930,13 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, |
799 |
error (EXIT_FAILURE, 0, |
800 |
gettext ("cannot get section header string table index")); |
801 |
|
802 |
- GElf_Shdr glink; |
803 |
+ GElf_Shdr glink_mem; |
804 |
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
805 |
+ &glink_mem); |
806 |
+ if (glink == NULL) |
807 |
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), |
808 |
+ elf_ndxscn (scn)); |
809 |
+ |
810 |
printf (ngettext ("\ |
811 |
\nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", |
812 |
"\ |
813 |
@@ -1931,9 +1947,7 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, |
814 |
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, |
815 |
shdr->sh_offset, |
816 |
(unsigned int) shdr->sh_link, |
817 |
- elf_strptr (ebl->elf, shstrndx, |
818 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
819 |
- &glink)->sh_name)); |
820 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
821 |
|
822 |
unsigned int offset = 0; |
823 |
for (int cnt = shdr->sh_info; --cnt >= 0; ) |
824 |
@@ -1986,8 +2000,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G |
825 |
error (EXIT_FAILURE, 0, |
826 |
gettext ("cannot get section header string table index")); |
827 |
|
828 |
+ GElf_Shdr glink_mem; |
829 |
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
830 |
+ &glink_mem); |
831 |
+ if (glink == NULL) |
832 |
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), |
833 |
+ elf_ndxscn (scn)); |
834 |
+ |
835 |
int class = gelf_getclass (ebl->elf); |
836 |
- GElf_Shdr glink; |
837 |
printf (ngettext ("\ |
838 |
\nVersion definition section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", |
839 |
"\ |
840 |
@@ -1999,9 +2019,7 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G |
841 |
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, |
842 |
shdr->sh_offset, |
843 |
(unsigned int) shdr->sh_link, |
844 |
- elf_strptr (ebl->elf, shstrndx, |
845 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
846 |
- &glink)->sh_name)); |
847 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
848 |
|
849 |
unsigned int offset = 0; |
850 |
for (int cnt = shdr->sh_info; --cnt >= 0; ) |
851 |
@@ -2263,8 +2281,14 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G |
852 |
filename = NULL; |
853 |
} |
854 |
|
855 |
+ GElf_Shdr glink_mem; |
856 |
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
857 |
+ &glink_mem); |
858 |
+ if (glink == NULL) |
859 |
+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), |
860 |
+ elf_ndxscn (scn)); |
861 |
+ |
862 |
/* Print the header. */ |
863 |
- GElf_Shdr glink; |
864 |
printf (ngettext ("\ |
865 |
\nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'", |
866 |
"\ |
867 |
@@ -2276,9 +2300,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G |
868 |
class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, |
869 |
shdr->sh_offset, |
870 |
(unsigned int) shdr->sh_link, |
871 |
- elf_strptr (ebl->elf, shstrndx, |
872 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
873 |
- &glink)->sh_name)); |
874 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
875 |
|
876 |
/* Now we can finally look at the actual contents of this section. */ |
877 |
for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
878 |
@@ -2330,7 +2352,17 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, |
879 |
for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt) |
880 |
++counts[lengths[cnt]]; |
881 |
|
882 |
- GElf_Shdr glink; |
883 |
+ GElf_Shdr glink_mem; |
884 |
+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, |
885 |
+ shdr->sh_link), |
886 |
+ &glink_mem); |
887 |
+ if (glink == NULL) |
888 |
+ { |
889 |
+ error (0, 0, gettext ("invalid sh_link value in section %Zu"), |
890 |
+ elf_ndxscn (scn)); |
891 |
+ return; |
892 |
+ } |
893 |
+ |
894 |
printf (ngettext ("\ |
895 |
\nHistogram for bucket list length in section [%2u] '%s' (total of %d bucket):\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", |
896 |
"\ |
897 |
@@ -2343,9 +2375,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, |
898 |
shdr->sh_addr, |
899 |
shdr->sh_offset, |
900 |
(unsigned int) shdr->sh_link, |
901 |
- elf_strptr (ebl->elf, shstrndx, |
902 |
- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), |
903 |
- &glink)->sh_name)); |
904 |
+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); |
905 |
|
906 |
if (extrastr != NULL) |
907 |
fputs (extrastr, stdout); |
908 |
@@ -3655,6 +3685,16 @@ print_debug_aranges_section (Ebl *ebl __ |
909 |
return; |
910 |
} |
911 |
|
912 |
+ GElf_Shdr glink_mem; |
913 |
+ GElf_Shdr *glink; |
914 |
+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); |
915 |
+ if (glink == NULL) |
916 |
+ { |
917 |
+ error (0, 0, gettext ("invalid sh_link value in section %Zu"), |
918 |
+ elf_ndxscn (scn)); |
919 |
+ return; |
920 |
+ } |
921 |
+ |
922 |
printf (ngettext ("\ |
923 |
\nDWARF section '%s' at offset %#" PRIx64 " contains %zu entry:\n", |
924 |
"\ |
925 |
--- elfutils-0.127/src/strip.c.robustify |
926 |
+++ elfutils-0.127/src/strip.c |
927 |
@@ -412,6 +412,7 @@ handle_elf (int fd, Elf *elf, const char |
928 |
Elf_Data debuglink_crc_data; |
929 |
bool any_symtab_changes = false; |
930 |
Elf_Data *shstrtab_data = NULL; |
931 |
+ size_t shdridx = 0; |
932 |
|
933 |
/* Create the full name of the file. */ |
934 |
if (prefix != NULL) |
935 |
@@ -542,6 +543,11 @@ handle_elf (int fd, Elf *elf, const char |
936 |
goto fail_close; |
937 |
} |
938 |
|
939 |
+ if (shstrndx >= shnum) |
940 |
+ goto illformed; |
941 |
+ |
942 |
+#define elf_assert(test) do { if (!(test)) goto illformed; } while (0) |
943 |
+ |
944 |
/* Storage for section information. We leave room for two more |
945 |
entries since we unconditionally create a section header string |
946 |
table. Maybe some weird tool created an ELF file without one. |
947 |
@@ -563,7 +569,7 @@ handle_elf (int fd, Elf *elf, const char |
948 |
{ |
949 |
/* This should always be true (i.e., there should not be any |
950 |
holes in the numbering). */ |
951 |
- assert (elf_ndxscn (scn) == cnt); |
952 |
+ elf_assert (elf_ndxscn (scn) == cnt); |
953 |
|
954 |
shdr_info[cnt].scn = scn; |
955 |
|
956 |
@@ -576,6 +582,7 @@ handle_elf (int fd, Elf *elf, const char |
957 |
shdr_info[cnt].shdr.sh_name); |
958 |
if (shdr_info[cnt].name == NULL) |
959 |
{ |
960 |
+ illformed: |
961 |
error (0, 0, gettext ("illformed file '%s'"), fname); |
962 |
goto fail_close; |
963 |
} |
964 |
@@ -585,6 +592,8 @@ handle_elf (int fd, Elf *elf, const char |
965 |
|
966 |
/* Remember the shdr.sh_link value. */ |
967 |
shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link; |
968 |
+ if (shdr_info[cnt].old_sh_link >= shnum) |
969 |
+ goto illformed; |
970 |
|
971 |
/* Sections in files other than relocatable object files which |
972 |
are not loaded can be freely moved by us. In relocatable |
973 |
@@ -597,7 +606,7 @@ handle_elf (int fd, Elf *elf, const char |
974 |
appropriate reference. */ |
975 |
if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX)) |
976 |
{ |
977 |
- assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); |
978 |
+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); |
979 |
shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt; |
980 |
} |
981 |
else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP)) |
982 |
@@ -614,7 +623,12 @@ handle_elf (int fd, Elf *elf, const char |
983 |
for (inner = 1; |
984 |
inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); |
985 |
++inner) |
986 |
+ { |
987 |
+ if (grpref[inner] < shnum) |
988 |
shdr_info[grpref[inner]].group_idx = cnt; |
989 |
+ else |
990 |
+ goto illformed; |
991 |
+ } |
992 |
|
993 |
if (inner == 1 || (inner == 2 && (grpref[0] & GRP_COMDAT) == 0)) |
994 |
/* If the section group contains only one element and this |
995 |
@@ -625,7 +639,7 @@ handle_elf (int fd, Elf *elf, const char |
996 |
} |
997 |
else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym)) |
998 |
{ |
999 |
- assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); |
1000 |
+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); |
1001 |
shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt; |
1002 |
} |
1003 |
|
1004 |
@@ -633,7 +647,7 @@ handle_elf (int fd, Elf *elf, const char |
1005 |
discarded right away. */ |
1006 |
if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0) |
1007 |
{ |
1008 |
- assert (shdr_info[cnt].group_idx != 0); |
1009 |
+ elf_assert (shdr_info[cnt].group_idx != 0); |
1010 |
|
1011 |
if (shdr_info[shdr_info[cnt].group_idx].idx == 0) |
1012 |
{ |
1013 |
@@ -708,11 +722,15 @@ handle_elf (int fd, Elf *elf, const char |
1014 |
{ |
1015 |
/* If a relocation section is marked as being removed make |
1016 |
sure the section it is relocating is removed, too. */ |
1017 |
- if ((shdr_info[cnt].shdr.sh_type == SHT_REL |
1018 |
+ if (shdr_info[cnt].shdr.sh_type == SHT_REL |
1019 |
|| shdr_info[cnt].shdr.sh_type == SHT_RELA) |
1020 |
- && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) |
1021 |
+ { |
1022 |
+ if (shdr_info[cnt].shdr.sh_info >= shnum) |
1023 |
+ goto illformed; |
1024 |
+ else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) |
1025 |
shdr_info[cnt].idx = 1; |
1026 |
} |
1027 |
+ } |
1028 |
|
1029 |
if (shdr_info[cnt].idx == 1) |
1030 |
{ |
1031 |
@@ -737,7 +755,7 @@ handle_elf (int fd, Elf *elf, const char |
1032 |
if (shdr_info[cnt].symtab_idx != 0 |
1033 |
&& shdr_info[shdr_info[cnt].symtab_idx].data == NULL) |
1034 |
{ |
1035 |
- assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); |
1036 |
+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); |
1037 |
|
1038 |
shdr_info[shdr_info[cnt].symtab_idx].data |
1039 |
= elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, |
1040 |
@@ -777,6 +795,9 @@ handle_elf (int fd, Elf *elf, const char |
1041 |
else if (scnidx == SHN_XINDEX) |
1042 |
scnidx = xndx; |
1043 |
|
1044 |
+ if (scnidx >= shnum) |
1045 |
+ goto illformed; |
1046 |
+ |
1047 |
if (shdr_info[scnidx].idx == 0) |
1048 |
{ |
1049 |
/* Mark this section as used. */ |
1050 |
@@ -808,12 +829,16 @@ handle_elf (int fd, Elf *elf, const char |
1051 |
} |
1052 |
|
1053 |
/* Handle references through sh_info. */ |
1054 |
- if (SH_INFO_LINK_P (&shdr_info[cnt].shdr) |
1055 |
- && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) |
1056 |
+ if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) |
1057 |
+ { |
1058 |
+ if (shdr_info[cnt].shdr.sh_info >= shnum) |
1059 |
+ goto illformed; |
1060 |
+ else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) |
1061 |
{ |
1062 |
shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1; |
1063 |
changes |= shdr_info[cnt].shdr.sh_info < cnt; |
1064 |
} |
1065 |
+ } |
1066 |
|
1067 |
/* Mark the section as investigated. */ |
1068 |
shdr_info[cnt].idx = 2; |
1069 |
@@ -912,7 +937,7 @@ handle_elf (int fd, Elf *elf, const char |
1070 |
error (EXIT_FAILURE, 0, gettext ("while generating output file: %s"), |
1071 |
elf_errmsg (-1)); |
1072 |
|
1073 |
- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); |
1074 |
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); |
1075 |
|
1076 |
/* Add this name to the section header string table. */ |
1077 |
shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0); |
1078 |
@@ -949,7 +974,7 @@ handle_elf (int fd, Elf *elf, const char |
1079 |
error (EXIT_FAILURE, 0, |
1080 |
gettext ("while create section header section: %s"), |
1081 |
elf_errmsg (-1)); |
1082 |
- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); |
1083 |
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); |
1084 |
|
1085 |
shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn); |
1086 |
if (shdr_info[cnt].data == NULL) |
1087 |
@@ -980,7 +1005,7 @@ handle_elf (int fd, Elf *elf, const char |
1088 |
} |
1089 |
|
1090 |
/* Index of the section header table in the shdr_info array. */ |
1091 |
- size_t shdridx = cnt; |
1092 |
+ shdridx = cnt; |
1093 |
|
1094 |
/* Add the section header string table section name. */ |
1095 |
shdr_info[cnt].se = ebl_strtabadd (shst, ".shstrtab", 10); |
1096 |
@@ -1005,7 +1030,7 @@ handle_elf (int fd, Elf *elf, const char |
1097 |
error (EXIT_FAILURE, 0, |
1098 |
gettext ("while create section header section: %s"), |
1099 |
elf_errmsg (-1)); |
1100 |
- assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); |
1101 |
+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); |
1102 |
|
1103 |
/* Finalize the string table and fill in the correct indices in the |
1104 |
section headers. */ |
1105 |
@@ -1095,20 +1120,20 @@ handle_elf (int fd, Elf *elf, const char |
1106 |
shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, |
1107 |
NULL); |
1108 |
|
1109 |
- assert ((versiondata->d_size / sizeof (Elf32_Word)) |
1110 |
+ elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) |
1111 |
>= shdr_info[cnt].data->d_size / elsize); |
1112 |
} |
1113 |
|
1114 |
if (shdr_info[cnt].version_idx != 0) |
1115 |
{ |
1116 |
- assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); |
1117 |
+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); |
1118 |
/* This section has associated version |
1119 |
information. We have to modify that |
1120 |
information, too. */ |
1121 |
versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn, |
1122 |
NULL); |
1123 |
|
1124 |
- assert ((versiondata->d_size / sizeof (GElf_Versym)) |
1125 |
+ elf_assert ((versiondata->d_size / sizeof (GElf_Versym)) |
1126 |
>= shdr_info[cnt].data->d_size / elsize); |
1127 |
} |
1128 |
|
1129 |
@@ -1163,7 +1188,7 @@ handle_elf (int fd, Elf *elf, const char |
1130 |
sec = shdr_info[sym->st_shndx].idx; |
1131 |
else |
1132 |
{ |
1133 |
- assert (shndxdata != NULL); |
1134 |
+ elf_assert (shndxdata != NULL); |
1135 |
|
1136 |
sec = shdr_info[xshndx].idx; |
1137 |
} |
1138 |
@@ -1184,7 +1209,7 @@ handle_elf (int fd, Elf *elf, const char |
1139 |
nxshndx = sec; |
1140 |
} |
1141 |
|
1142 |
- assert (sec < SHN_LORESERVE || shndxdata != NULL); |
1143 |
+ elf_assert (sec < SHN_LORESERVE || shndxdata != NULL); |
1144 |
|
1145 |
if ((inner != destidx || nshndx != sym->st_shndx |
1146 |
|| (shndxdata != NULL && nxshndx != xshndx)) |
1147 |
@@ -1207,7 +1232,7 @@ handle_elf (int fd, Elf *elf, const char |
1148 |
else |
1149 |
/* This is a section symbol for a section which has |
1150 |
been removed. */ |
1151 |
- assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); |
1152 |
+ elf_assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); |
1153 |
} |
1154 |
|
1155 |
if (destidx != inner) |
1156 |
@@ -1371,11 +1396,11 @@ handle_elf (int fd, Elf *elf, const char |
1157 |
{ |
1158 |
GElf_Sym sym_mem; |
1159 |
GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); |
1160 |
- assert (sym != NULL); |
1161 |
+ elf_assert (sym != NULL); |
1162 |
|
1163 |
const char *name = elf_strptr (elf, strshndx, |
1164 |
sym->st_name); |
1165 |
- assert (name != NULL); |
1166 |
+ elf_assert (name != NULL); |
1167 |
size_t hidx = elf_hash (name) % nbucket; |
1168 |
|
1169 |
if (bucket[hidx] == 0) |
1170 |
@@ -1394,7 +1419,7 @@ handle_elf (int fd, Elf *elf, const char |
1171 |
else |
1172 |
{ |
1173 |
/* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */ |
1174 |
- assert (shdr_info[cnt].shdr.sh_entsize |
1175 |
+ elf_assert (shdr_info[cnt].shdr.sh_entsize |
1176 |
== sizeof (Elf64_Xword)); |
1177 |
|
1178 |
Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf; |
1179 |
@@ -1428,11 +1453,11 @@ handle_elf (int fd, Elf *elf, const char |
1180 |
{ |
1181 |
GElf_Sym sym_mem; |
1182 |
GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); |
1183 |
- assert (sym != NULL); |
1184 |
+ elf_assert (sym != NULL); |
1185 |
|
1186 |
const char *name = elf_strptr (elf, strshndx, |
1187 |
sym->st_name); |
1188 |
- assert (name != NULL); |
1189 |
+ elf_assert (name != NULL); |
1190 |
size_t hidx = elf_hash (name) % nbucket; |
1191 |
|
1192 |
if (bucket[hidx] == 0) |
1193 |
--- elfutils-0.127/src/elflint.c.robustify |
1194 |
+++ elfutils-0.127/src/elflint.c |
1195 |
@@ -123,6 +123,9 @@ static uint32_t shstrndx; |
1196 |
/* Array to count references in section groups. */ |
1197 |
static int *scnref; |
1198 |
|
1199 |
+/* Number of sections. */ |
1200 |
+static unsigned int shnum; |
1201 |
+ |
1202 |
|
1203 |
int |
1204 |
main (int argc, char *argv[]) |
1205 |
@@ -312,10 +315,19 @@ section_name (Ebl *ebl, int idx) |
1206 |
{ |
1207 |
GElf_Shdr shdr_mem; |
1208 |
GElf_Shdr *shdr; |
1209 |
+ const char *ret; |
1210 |
+ |
1211 |
+ if ((unsigned int) idx > shnum) |
1212 |
+ return "<invalid>"; |
1213 |
|
1214 |
shdr = gelf_getshdr (elf_getscn (ebl->elf, idx), &shdr_mem); |
1215 |
+ if (shdr == NULL) |
1216 |
+ return "<invalid>"; |
1217 |
|
1218 |
- return elf_strptr (ebl->elf, shstrndx, shdr->sh_name); |
1219 |
+ ret = elf_strptr (ebl->elf, shstrndx, shdr->sh_name); |
1220 |
+ if (ret == NULL) |
1221 |
+ return "<invalid>"; |
1222 |
+ return ret; |
1223 |
} |
1224 |
|
1225 |
|
1226 |
@@ -337,10 +349,6 @@ static const int valid_e_machine[] = |
1227 |
(sizeof (valid_e_machine) / sizeof (valid_e_machine[0])) |
1228 |
|
1229 |
|
1230 |
-/* Number of sections. */ |
1231 |
-static unsigned int shnum; |
1232 |
- |
1233 |
- |
1234 |
static void |
1235 |
check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size) |
1236 |
{ |
1237 |
@@ -603,7 +611,8 @@ section [%2d] '%s': symbol table cannot |
1238 |
} |
1239 |
} |
1240 |
|
1241 |
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT)) |
1242 |
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT); |
1243 |
+ if (shdr->sh_entsize != sh_entsize) |
1244 |
ERROR (gettext ("\ |
1245 |
section [%2zu] '%s': entry size is does not match ElfXX_Sym\n"), |
1246 |
cnt, section_name (ebl, cnt)); |
1247 |
@@ -641,7 +650,7 @@ section [%2d] '%s': XINDEX for zeroth en |
1248 |
xndxscnidx, section_name (ebl, xndxscnidx)); |
1249 |
} |
1250 |
|
1251 |
- for (cnt = 1; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
1252 |
+ for (cnt = 1; cnt < shdr->sh_size / sh_entsize; ++cnt) |
1253 |
{ |
1254 |
sym = gelf_getsymshndx (data, xndxdata, cnt, &sym_mem, &xndx); |
1255 |
if (sym == NULL) |
1256 |
@@ -659,7 +668,8 @@ section [%2d] '%s': symbol %zu: invalid |
1257 |
else |
1258 |
{ |
1259 |
name = elf_strptr (ebl->elf, shdr->sh_link, sym->st_name); |
1260 |
- assert (name != NULL); |
1261 |
+ assert (name != NULL |
1262 |
+ || strshdr->sh_type != SHT_STRTAB); |
1263 |
} |
1264 |
|
1265 |
if (sym->st_shndx == SHN_XINDEX) |
1266 |
@@ -981,9 +991,11 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e |
1267 |
{ |
1268 |
GElf_Shdr rcshdr_mem; |
1269 |
const GElf_Shdr *rcshdr = gelf_getshdr (scn, &rcshdr_mem); |
1270 |
- assert (rcshdr != NULL); |
1271 |
|
1272 |
- if (rcshdr->sh_type == SHT_DYNAMIC) |
1273 |
+ if (rcshdr == NULL) |
1274 |
+ break; |
1275 |
+ |
1276 |
+ if (rcshdr->sh_type == SHT_DYNAMIC && rcshdr->sh_entsize) |
1277 |
{ |
1278 |
/* Found the dynamic section. Look through it. */ |
1279 |
Elf_Data *d = elf_getdata (scn, NULL); |
1280 |
@@ -993,7 +1005,9 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e |
1281 |
{ |
1282 |
GElf_Dyn dyn_mem; |
1283 |
GElf_Dyn *dyn = gelf_getdyn (d, cnt, &dyn_mem); |
1284 |
- assert (dyn != NULL); |
1285 |
+ |
1286 |
+ if (dyn == NULL) |
1287 |
+ break; |
1288 |
|
1289 |
if (dyn->d_tag == DT_RELCOUNT) |
1290 |
{ |
1291 |
@@ -1007,7 +1021,9 @@ section [%2d] '%s': DT_RELCOUNT used for |
1292 |
/* Does the number specified number of relative |
1293 |
relocations exceed the total number of |
1294 |
relocations? */ |
1295 |
- if (dyn->d_un.d_val > shdr->sh_size / shdr->sh_entsize) |
1296 |
+ if (shdr->sh_entsize != 0 |
1297 |
+ && dyn->d_un.d_val > (shdr->sh_size |
1298 |
+ / shdr->sh_entsize)) |
1299 |
ERROR (gettext ("\ |
1300 |
section [%2d] '%s': DT_RELCOUNT value %d too high for this section\n"), |
1301 |
idx, section_name (ebl, idx), |
1302 |
@@ -1167,7 +1183,8 @@ section [%2d] '%s': no relocations for m |
1303 |
} |
1304 |
} |
1305 |
|
1306 |
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT)) |
1307 |
+ size_t sh_entsize = gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT); |
1308 |
+ if (shdr->sh_entsize != sh_entsize) |
1309 |
ERROR (gettext (reltype == ELF_T_RELA ? "\ |
1310 |
section [%2d] '%s': section entry size does not match ElfXX_Rela\n" : "\ |
1311 |
section [%2d] '%s': section entry size does not match ElfXX_Rel\n"), |
1312 |
@@ -1389,7 +1406,8 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, G |
1313 |
Elf_Data *symdata = elf_getdata (symscn, NULL); |
1314 |
enum load_state state = state_undecided; |
1315 |
|
1316 |
- for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
1317 |
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT); |
1318 |
+ for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt) |
1319 |
{ |
1320 |
GElf_Rela rela_mem; |
1321 |
GElf_Rela *rela = gelf_getrela (data, cnt, &rela_mem); |
1322 |
@@ -1439,7 +1457,8 @@ check_rel (Ebl *ebl, GElf_Ehdr *ehdr, GE |
1323 |
Elf_Data *symdata = elf_getdata (symscn, NULL); |
1324 |
enum load_state state = state_undecided; |
1325 |
|
1326 |
- for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
1327 |
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT); |
1328 |
+ for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt) |
1329 |
{ |
1330 |
GElf_Rel rel_mem; |
1331 |
GElf_Rel *rel = gelf_getrel (data, cnt, &rel_mem); |
1332 |
@@ -1543,7 +1562,8 @@ section [%2d] '%s': referenced as string |
1333 |
shdr->sh_link, section_name (ebl, shdr->sh_link), |
1334 |
idx, section_name (ebl, idx)); |
1335 |
|
1336 |
- if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT)) |
1337 |
+ size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT); |
1338 |
+ if (shdr->sh_entsize != sh_entsize) |
1339 |
ERROR (gettext ("\ |
1340 |
section [%2d] '%s': section entry size does not match ElfXX_Dyn\n"), |
1341 |
idx, section_name (ebl, idx)); |
1342 |
@@ -1553,7 +1573,7 @@ section [%2d] '%s': section entry size d |
1343 |
idx, section_name (ebl, idx)); |
1344 |
|
1345 |
bool non_null_warned = false; |
1346 |
- for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) |
1347 |
+ for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt) |
1348 |
{ |
1349 |
GElf_Dyn dyn_mem; |
1350 |
GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dyn_mem); |
1351 |
@@ -1834,6 +1854,8 @@ section [%2d] '%s': entry size does not |
1352 |
idx, section_name (ebl, idx)); |
1353 |
|
1354 |
if (symshdr != NULL |
1355 |
+ && shdr->sh_entsize |
1356 |
+ && symshdr->sh_entsize |
1357 |
&& (shdr->sh_size / shdr->sh_entsize |
1358 |
< symshdr->sh_size / symshdr->sh_entsize)) |
1359 |
ERROR (gettext ("\ |
1360 |
@@ -1860,6 +1882,12 @@ section [%2d] '%s': extended section ind |
1361 |
} |
1362 |
|
1363 |
Elf_Data *data = elf_getdata (elf_getscn (ebl->elf, idx), NULL); |
1364 |
+ if (data == NULL) |
1365 |
+ { |
1366 |
+ ERROR (gettext ("section [%2d] '%s': cannot get section data\n"), |
1367 |
+ idx, section_name (ebl, idx)); |
1368 |
+ return; |
1369 |
+ } |
1370 |
|
1371 |
if (*((Elf32_Word *) data->d_buf) != 0) |
1372 |
ERROR (gettext ("symbol 0 should have zero extended section index\n")); |
1373 |
@@ -1902,7 +1930,7 @@ section [%2d] '%s': hash table section i |
1374 |
|
1375 |
size_t maxidx = nchain; |
1376 |
|
1377 |
- if (symshdr != NULL) |
1378 |
+ if (symshdr != NULL && symshdr->sh_entsize != 0) |
1379 |
{ |
1380 |
size_t symsize = symshdr->sh_size / symshdr->sh_entsize; |
1381 |
|
1382 |
@@ -1913,18 +1941,28 @@ section [%2d] '%s': hash table section i |
1383 |
maxidx = symsize; |
1384 |
} |
1385 |
|
1386 |
+ Elf32_Word *buf = (Elf32_Word *) data->d_buf; |
1387 |
+ Elf32_Word *end = (Elf32_Word *) ((char *) data->d_buf + shdr->sh_size); |
1388 |
size_t cnt; |
1389 |
for (cnt = 2; cnt < 2 + nbucket; ++cnt) |
1390 |
- if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx) |
1391 |
+ { |
1392 |
+ if (buf + cnt >= end) |
1393 |
+ break; |
1394 |
+ else if (buf[cnt] >= maxidx) |
1395 |
ERROR (gettext ("\ |
1396 |
section [%2d] '%s': hash bucket reference %zu out of bounds\n"), |
1397 |
idx, section_name (ebl, idx), cnt - 2); |
1398 |
+ } |
1399 |
|
1400 |
for (; cnt < 2 + nbucket + nchain; ++cnt) |
1401 |
- if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx) |
1402 |
+ { |
1403 |
+ if (buf + cnt >= end) |
1404 |
+ break; |
1405 |
+ else if (buf[cnt] >= maxidx) |
1406 |
ERROR (gettext ("\ |
1407 |
section [%2d] '%s': hash chain reference %zu out of bounds\n"), |
1408 |
idx, section_name (ebl, idx), cnt - 2 - nbucket); |
1409 |
+ } |
1410 |
} |
1411 |
|
1412 |
|
1413 |
@@ -1954,18 +1992,28 @@ section [%2d] '%s': hash table section i |
1414 |
maxidx = symsize; |
1415 |
} |
1416 |
|
1417 |
+ Elf64_Xword *buf = (Elf64_Xword *) data->d_buf; |
1418 |
+ Elf64_Xword *end = (Elf64_Xword *) ((char *) data->d_buf + shdr->sh_size); |
1419 |
size_t cnt; |
1420 |
for (cnt = 2; cnt < 2 + nbucket; ++cnt) |
1421 |
- if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx) |
1422 |
+ { |
1423 |
+ if (buf + cnt >= end) |
1424 |
+ break; |
1425 |
+ else if (buf[cnt] >= maxidx) |
1426 |
ERROR (gettext ("\ |
1427 |
section [%2d] '%s': hash bucket reference %zu out of bounds\n"), |
1428 |
idx, section_name (ebl, idx), cnt - 2); |
1429 |
+ } |
1430 |
|
1431 |
for (; cnt < 2 + nbucket + nchain; ++cnt) |
1432 |
- if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx) |
1433 |
+ { |
1434 |
+ if (buf + cnt >= end) |
1435 |
+ break; |
1436 |
+ else if (buf[cnt] >= maxidx) |
1437 |
ERROR (gettext ("\ |
1438 |
section [%2d] '%s': hash chain reference %" PRIu64 " out of bounds\n"), |
1439 |
- idx, section_name (ebl, idx), (uint64_t) (cnt - 2 - nbucket)); |
1440 |
+ idx, section_name (ebl, idx), (uint64_t) cnt - 2 - nbucket); |
1441 |
+ } |
1442 |
} |
1443 |
|
1444 |
|
1445 |
@@ -1990,7 +2038,7 @@ section [%2d] '%s': bitmask size not pow |
1446 |
if (shdr->sh_size < (4 + bitmask_words + nbuckets) * sizeof (Elf32_Word)) |
1447 |
{ |
1448 |
ERROR (gettext ("\ |
1449 |
-section [%2d] '%s': hash table section is too small (is %ld, expected at least%ld)\n"), |
1450 |
+section [%2d] '%s': hash table section is too small (is %ld, expected at least %ld)\n"), |
1451 |
idx, section_name (ebl, idx), (long int) shdr->sh_size, |
1452 |
(long int) ((4 + bitmask_words + nbuckets) * sizeof (Elf32_Word))); |
1453 |
return; |
1454 |
@@ -2644,8 +2692,9 @@ section [%2d] '%s' refers in sh_link to |
1455 |
|
1456 |
/* The number of elements in the version symbol table must be the |
1457 |
same as the number of symbols. */ |
1458 |
- if (shdr->sh_size / shdr->sh_entsize |
1459 |
- != symshdr->sh_size / symshdr->sh_entsize) |
1460 |
+ if (shdr->sh_entsize && symshdr->sh_entsize |
1461 |
+ && (shdr->sh_size / shdr->sh_entsize |
1462 |
+ != symshdr->sh_size / symshdr->sh_entsize)) |
1463 |
ERROR (gettext ("\ |
1464 |
section [%2d] '%s' has different number of entries than symbol table [%2d] '%s'\n"), |
1465 |
idx, section_name (ebl, idx), |
1466 |
--- elfutils-0.127/libelf/elf_begin.c.robustify |
1467 |
+++ elfutils-0.127/libelf/elf_begin.c |
1468 |
@@ -155,7 +155,8 @@ get_shnum (void *map_address, unsigned c |
1469 |
|
1470 |
if (unlikely (result == 0) && ehdr.e32->e_shoff != 0) |
1471 |
{ |
1472 |
- if (ehdr.e32->e_shoff + sizeof (Elf32_Shdr) > maxsize) |
1473 |
+ if (unlikely (ehdr.e32->e_shoff >= maxsize) |
1474 |
+ || unlikely (ehdr.e32->e_shoff + sizeof (Elf32_Shdr) > maxsize)) |
1475 |
/* Cannot read the first section header. */ |
1476 |
return 0; |
1477 |
|
1478 |
@@ -203,7 +204,8 @@ get_shnum (void *map_address, unsigned c |
1479 |
|
1480 |
if (unlikely (result == 0) && ehdr.e64->e_shoff != 0) |
1481 |
{ |
1482 |
- if (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize) |
1483 |
+ if (unlikely (ehdr.e64->e_shoff >= maxsize) |
1484 |
+ || unlikely (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize)) |
1485 |
/* Cannot read the first section header. */ |
1486 |
return 0; |
1487 |
|
1488 |
@@ -275,6 +277,15 @@ file_read_elf (int fildes, void *map_add |
1489 |
/* Could not determine the number of sections. */ |
1490 |
return NULL; |
1491 |
|
1492 |
+ /* Check for too many sections. */ |
1493 |
+ if (e_ident[EI_CLASS] == ELFCLASS32) |
1494 |
+ { |
1495 |
+ if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf32_Shdr))) |
1496 |
+ return NULL; |
1497 |
+ } |
1498 |
+ else if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf64_Shdr))) |
1499 |
+ return NULL; |
1500 |
+ |
1501 |
/* We can now allocate the memory. */ |
1502 |
Elf *elf = allocate_elf (fildes, map_address, offset, maxsize, cmd, parent, |
1503 |
ELF_K_ELF, scncnt * sizeof (Elf_Scn)); |
1504 |
@@ -308,13 +319,31 @@ file_read_elf (int fildes, void *map_add |
1505 |
{ |
1506 |
/* We can use the mmapped memory. */ |
1507 |
elf->state.elf32.ehdr = ehdr; |
1508 |
+ |
1509 |
+ if (unlikely (ehdr->e_shoff >= maxsize) |
1510 |
+ || unlikely (ehdr->e_shoff |
1511 |
+ + scncnt * sizeof (Elf32_Shdr) > maxsize)) |
1512 |
+ { |
1513 |
+ free_and_out: |
1514 |
+ free (elf); |
1515 |
+ __libelf_seterrno (ELF_E_INVALID_FILE); |
1516 |
+ return NULL; |
1517 |
+ } |
1518 |
elf->state.elf32.shdr |
1519 |
= (Elf32_Shdr *) ((char *) ehdr + ehdr->e_shoff); |
1520 |
+ |
1521 |
if (ehdr->e_phnum > 0) |
1522 |
+ { |
1523 |
/* Assign a value only if there really is a program |
1524 |
header. Otherwise the value remains NULL. */ |
1525 |
+ if (unlikely (ehdr->e_phoff >= maxsize) |
1526 |
+ || unlikely (ehdr->e_phoff |
1527 |
+ + ehdr->e_phnum |
1528 |
+ * sizeof (Elf32_Phdr) > maxsize)) |
1529 |
+ goto free_and_out; |
1530 |
elf->state.elf32.phdr |
1531 |
= (Elf32_Phdr *) ((char *) ehdr + ehdr->e_phoff); |
1532 |
+ } |
1533 |
|
1534 |
for (size_t cnt = 0; cnt < scncnt; ++cnt) |
1535 |
{ |
1536 |
@@ -383,13 +412,26 @@ file_read_elf (int fildes, void *map_add |
1537 |
{ |
1538 |
/* We can use the mmapped memory. */ |
1539 |
elf->state.elf64.ehdr = ehdr; |
1540 |
+ |
1541 |
+ if (unlikely (ehdr->e_shoff >= maxsize) |
1542 |
+ || unlikely (ehdr->e_shoff |
1543 |
+ + scncnt * sizeof (Elf32_Shdr) > maxsize)) |
1544 |
+ goto free_and_out; |
1545 |
elf->state.elf64.shdr |
1546 |
= (Elf64_Shdr *) ((char *) ehdr + ehdr->e_shoff); |
1547 |
+ |
1548 |
if (ehdr->e_phnum > 0) |
1549 |
+ { |
1550 |
/* Assign a value only if there really is a program |
1551 |
header. Otherwise the value remains NULL. */ |
1552 |
+ if (unlikely (ehdr->e_phoff >= maxsize) |
1553 |
+ || unlikely (ehdr->e_phoff |
1554 |
+ + ehdr->e_phnum |
1555 |
+ * sizeof (Elf32_Phdr) > maxsize)) |
1556 |
+ goto free_and_out; |
1557 |
elf->state.elf64.phdr |
1558 |
= (Elf64_Phdr *) ((char *) ehdr + ehdr->e_phoff); |
1559 |
+ } |
1560 |
|
1561 |
for (size_t cnt = 0; cnt < scncnt; ++cnt) |
1562 |
{ |
1563 |
--- elfutils-0.127/libelf/libelfP.h.robustify |
1564 |
+++ elfutils-0.127/libelf/libelfP.h |
1565 |
@@ -574,4 +574,13 @@ extern uint32_t __libelf_crc32 (uint32_t |
1566 |
} \ |
1567 |
} while (0) |
1568 |
|
1569 |
+/* Convenience macro. Assumes int NDX and TYPE with size at least |
1570 |
+ 2 bytes. */ |
1571 |
+#if SIZE_MAX > 4294967295U |
1572 |
+# define INVALID_NDX(ndx, type) unlikely (ndx < 0) |
1573 |
+#else |
1574 |
+# define INVALID_NDX(ndx, type) \ |
1575 |
+ unlikely ((unsigned int) (ndx) >= SIZE_MAX / sizeof (type)) |
1576 |
+#endif |
1577 |
+ |
1578 |
#endif /* libelfP.h */ |
1579 |
--- elfutils-0.127/libelf/gelf_update_move.c.robustify |
1580 |
+++ elfutils-0.127/libelf/gelf_update_move.c |
1581 |
@@ -75,7 +75,7 @@ gelf_update_move (data, ndx, src) |
1582 |
assert (sizeof (GElf_Move) == sizeof (Elf64_Move)); |
1583 |
|
1584 |
/* Check whether we have to resize the data buffer. */ |
1585 |
- if (unlikely (ndx < 0) |
1586 |
+ if (INVALID_NDX (ndx, GElf_Move) |
1587 |
|| unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size)) |
1588 |
{ |
1589 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1590 |
--- elfutils-0.127/libelf/gelf_getsym.c.robustify |
1591 |
+++ elfutils-0.127/libelf/gelf_getsym.c |
1592 |
@@ -90,7 +90,8 @@ gelf_getsym (data, ndx, dst) |
1593 |
table entries has to be adopted. The user better has provided |
1594 |
a buffer where we can store the information. While copying the |
1595 |
data we are converting the format. */ |
1596 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) |
1597 |
+ if (INVALID_NDX (ndx, Elf32_Sym) |
1598 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) |
1599 |
{ |
1600 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1601 |
goto out; |
1602 |
@@ -119,7 +120,8 @@ gelf_getsym (data, ndx, dst) |
1603 |
|
1604 |
/* The data is already in the correct form. Just make sure the |
1605 |
index is OK. */ |
1606 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) |
1607 |
+ if (INVALID_NDX (ndx, GElf_Sym) |
1608 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) |
1609 |
{ |
1610 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1611 |
goto out; |
1612 |
--- elfutils-0.127/libelf/gelf_getrela.c.robustify |
1613 |
+++ elfutils-0.127/libelf/gelf_getrela.c |
1614 |
@@ -71,12 +71,6 @@ gelf_getrela (data, ndx, dst) |
1615 |
if (data_scn == NULL) |
1616 |
return NULL; |
1617 |
|
1618 |
- if (unlikely (ndx < 0)) |
1619 |
- { |
1620 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1621 |
- return NULL; |
1622 |
- } |
1623 |
- |
1624 |
if (unlikely (data_scn->d.d_type != ELF_T_RELA)) |
1625 |
{ |
1626 |
__libelf_seterrno (ELF_E_INVALID_HANDLE); |
1627 |
@@ -93,7 +87,8 @@ gelf_getrela (data, ndx, dst) |
1628 |
if (scn->elf->class == ELFCLASS32) |
1629 |
{ |
1630 |
/* We have to convert the data. */ |
1631 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) |
1632 |
+ if (INVALID_NDX (ndx, Elf32_Rela) |
1633 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) |
1634 |
{ |
1635 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1636 |
result = NULL; |
1637 |
@@ -114,7 +109,8 @@ gelf_getrela (data, ndx, dst) |
1638 |
{ |
1639 |
/* Simply copy the data after we made sure we are actually getting |
1640 |
correct data. */ |
1641 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) |
1642 |
+ if (INVALID_NDX (ndx, Elf64_Rela) |
1643 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) |
1644 |
{ |
1645 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1646 |
result = NULL; |
1647 |
--- elfutils-0.127/libelf/gelf_getmove.c.robustify |
1648 |
+++ elfutils-0.127/libelf/gelf_getmove.c |
1649 |
@@ -83,7 +83,8 @@ gelf_getmove (data, ndx, dst) |
1650 |
|
1651 |
/* The data is already in the correct form. Just make sure the |
1652 |
index is OK. */ |
1653 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) |
1654 |
+ if (INVALID_NDX (ndx, GElf_Move) |
1655 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) |
1656 |
{ |
1657 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1658 |
goto out; |
1659 |
--- elfutils-0.127/libelf/gelf_update_symshndx.c.robustify |
1660 |
+++ elfutils-0.127/libelf/gelf_update_symshndx.c |
1661 |
@@ -77,12 +77,6 @@ gelf_update_symshndx (symdata, shndxdata |
1662 |
if (symdata == NULL) |
1663 |
return 0; |
1664 |
|
1665 |
- if (unlikely (ndx < 0)) |
1666 |
- { |
1667 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1668 |
- return 0; |
1669 |
- } |
1670 |
- |
1671 |
if (unlikely (symdata_scn->d.d_type != ELF_T_SYM)) |
1672 |
{ |
1673 |
/* The type of the data better should match. */ |
1674 |
@@ -128,7 +122,8 @@ gelf_update_symshndx (symdata, shndxdata |
1675 |
} |
1676 |
|
1677 |
/* Check whether we have to resize the data buffer. */ |
1678 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) |
1679 |
+ if (INVALID_NDX (ndx, Elf32_Sym) |
1680 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) |
1681 |
{ |
1682 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1683 |
goto out; |
1684 |
@@ -151,7 +146,8 @@ gelf_update_symshndx (symdata, shndxdata |
1685 |
else |
1686 |
{ |
1687 |
/* Check whether we have to resize the data buffer. */ |
1688 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) |
1689 |
+ if (INVALID_NDX (ndx, Elf64_Sym) |
1690 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) |
1691 |
{ |
1692 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1693 |
goto out; |
1694 |
--- elfutils-0.127/libelf/gelf_update_dyn.c.robustify |
1695 |
+++ elfutils-0.127/libelf/gelf_update_dyn.c |
1696 |
@@ -71,12 +71,6 @@ gelf_update_dyn (data, ndx, src) |
1697 |
if (data == NULL) |
1698 |
return 0; |
1699 |
|
1700 |
- if (unlikely (ndx < 0)) |
1701 |
- { |
1702 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1703 |
- return 0; |
1704 |
- } |
1705 |
- |
1706 |
if (unlikely (data_scn->d.d_type != ELF_T_DYN)) |
1707 |
{ |
1708 |
/* The type of the data better should match. */ |
1709 |
@@ -102,7 +96,8 @@ gelf_update_dyn (data, ndx, src) |
1710 |
} |
1711 |
|
1712 |
/* Check whether we have to resize the data buffer. */ |
1713 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) |
1714 |
+ if (INVALID_NDX (ndx, Elf32_Dyn) |
1715 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) |
1716 |
{ |
1717 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1718 |
goto out; |
1719 |
@@ -116,7 +111,8 @@ gelf_update_dyn (data, ndx, src) |
1720 |
else |
1721 |
{ |
1722 |
/* Check whether we have to resize the data buffer. */ |
1723 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) |
1724 |
+ if (INVALID_NDX (ndx, Elf64_Dyn) |
1725 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) |
1726 |
{ |
1727 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1728 |
goto out; |
1729 |
--- elfutils-0.127/libelf/gelf_update_rela.c.robustify |
1730 |
+++ elfutils-0.127/libelf/gelf_update_rela.c |
1731 |
@@ -68,12 +68,6 @@ gelf_update_rela (Elf_Data *dst, int ndx |
1732 |
if (dst == NULL) |
1733 |
return 0; |
1734 |
|
1735 |
- if (unlikely (ndx < 0)) |
1736 |
- { |
1737 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1738 |
- return 0; |
1739 |
- } |
1740 |
- |
1741 |
if (unlikely (data_scn->d.d_type != ELF_T_RELA)) |
1742 |
{ |
1743 |
/* The type of the data better should match. */ |
1744 |
@@ -101,7 +95,8 @@ gelf_update_rela (Elf_Data *dst, int ndx |
1745 |
} |
1746 |
|
1747 |
/* Check whether we have to resize the data buffer. */ |
1748 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) |
1749 |
+ if (INVALID_NDX (ndx, Elf32_Rela) |
1750 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) |
1751 |
{ |
1752 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1753 |
goto out; |
1754 |
@@ -117,7 +112,8 @@ gelf_update_rela (Elf_Data *dst, int ndx |
1755 |
else |
1756 |
{ |
1757 |
/* Check whether we have to resize the data buffer. */ |
1758 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) |
1759 |
+ if (INVALID_NDX (ndx, Elf64_Rela) |
1760 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) |
1761 |
{ |
1762 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1763 |
goto out; |
1764 |
--- elfutils-0.127/libelf/gelf_getsymshndx.c.robustify |
1765 |
+++ elfutils-0.127/libelf/gelf_getsymshndx.c |
1766 |
@@ -90,7 +90,9 @@ gelf_getsymshndx (symdata, shndxdata, nd |
1767 |
section index table. */ |
1768 |
if (likely (shndxdata_scn != NULL)) |
1769 |
{ |
1770 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size)) |
1771 |
+ if (INVALID_NDX (ndx, Elf32_Word) |
1772 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Word) |
1773 |
+ > shndxdata_scn->d.d_size)) |
1774 |
{ |
1775 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1776 |
goto out; |
1777 |
@@ -110,7 +112,8 @@ gelf_getsymshndx (symdata, shndxdata, nd |
1778 |
table entries has to be adopted. The user better has provided |
1779 |
a buffer where we can store the information. While copying the |
1780 |
data we are converting the format. */ |
1781 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) |
1782 |
+ if (INVALID_NDX (ndx, Elf32_Sym) |
1783 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) |
1784 |
{ |
1785 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1786 |
goto out; |
1787 |
@@ -139,7 +142,8 @@ gelf_getsymshndx (symdata, shndxdata, nd |
1788 |
|
1789 |
/* The data is already in the correct form. Just make sure the |
1790 |
index is OK. */ |
1791 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) |
1792 |
+ if (INVALID_NDX (ndx, GElf_Sym) |
1793 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) |
1794 |
{ |
1795 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1796 |
goto out; |
1797 |
--- elfutils-0.127/libelf/elf32_newphdr.c.robustify |
1798 |
+++ elfutils-0.127/libelf/elf32_newphdr.c |
1799 |
@@ -124,6 +124,12 @@ elfw2(LIBELFBITS,newphdr) (elf, count) |
1800 |
else if (elf->state.ELFW(elf,LIBELFBITS).ehdr->e_phnum != count |
1801 |
|| elf->state.ELFW(elf,LIBELFBITS).phdr == NULL) |
1802 |
{ |
1803 |
+ if (unlikely (count > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Phdr)))) |
1804 |
+ { |
1805 |
+ result = NULL; |
1806 |
+ goto out; |
1807 |
+ } |
1808 |
+ |
1809 |
/* Allocate a new program header with the appropriate number of |
1810 |
elements. */ |
1811 |
result = (ElfW2(LIBELFBITS,Phdr) *) |
1812 |
--- elfutils-0.127/libelf/gelf_update_sym.c.robustify |
1813 |
+++ elfutils-0.127/libelf/gelf_update_sym.c |
1814 |
@@ -72,12 +72,6 @@ gelf_update_sym (data, ndx, src) |
1815 |
if (data == NULL) |
1816 |
return 0; |
1817 |
|
1818 |
- if (unlikely (ndx < 0)) |
1819 |
- { |
1820 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1821 |
- return 0; |
1822 |
- } |
1823 |
- |
1824 |
if (unlikely (data_scn->d.d_type != ELF_T_SYM)) |
1825 |
{ |
1826 |
/* The type of the data better should match. */ |
1827 |
@@ -102,7 +96,8 @@ gelf_update_sym (data, ndx, src) |
1828 |
} |
1829 |
|
1830 |
/* Check whether we have to resize the data buffer. */ |
1831 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) |
1832 |
+ if (INVALID_NDX (ndx, Elf32_Sym) |
1833 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) |
1834 |
{ |
1835 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1836 |
goto out; |
1837 |
@@ -125,7 +120,8 @@ gelf_update_sym (data, ndx, src) |
1838 |
else |
1839 |
{ |
1840 |
/* Check whether we have to resize the data buffer. */ |
1841 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) |
1842 |
+ if (INVALID_NDX (ndx, Elf64_Sym) |
1843 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) |
1844 |
{ |
1845 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1846 |
goto out; |
1847 |
--- elfutils-0.127/libelf/gelf_getsyminfo.c.robustify |
1848 |
+++ elfutils-0.127/libelf/gelf_getsyminfo.c |
1849 |
@@ -84,7 +84,8 @@ gelf_getsyminfo (data, ndx, dst) |
1850 |
|
1851 |
/* The data is already in the correct form. Just make sure the |
1852 |
index is OK. */ |
1853 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) |
1854 |
+ if (INVALID_NDX (ndx, GElf_Syminfo) |
1855 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) |
1856 |
{ |
1857 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1858 |
goto out; |
1859 |
--- elfutils-0.127/libelf/gelf_getlib.c.robustify |
1860 |
+++ elfutils-0.127/libelf/gelf_getlib.c |
1861 |
@@ -86,7 +86,8 @@ gelf_getlib (data, ndx, dst) |
1862 |
/* The data is already in the correct form. Just make sure the |
1863 |
index is OK. */ |
1864 |
GElf_Lib *result = NULL; |
1865 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) |
1866 |
+ if (INVALID_NDX (ndx, GElf_Lib) |
1867 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) |
1868 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1869 |
else |
1870 |
{ |
1871 |
--- elfutils-0.127/libelf/elf32_updatefile.c.robustify |
1872 |
+++ elfutils-0.127/libelf/elf32_updatefile.c |
1873 |
@@ -201,6 +201,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf |
1874 |
/* Write all the sections. Well, only those which are modified. */ |
1875 |
if (shnum > 0) |
1876 |
{ |
1877 |
+ if (unlikely (shnum > SIZE_MAX / sizeof (Elf_Scn *))) |
1878 |
+ return 1; |
1879 |
+ |
1880 |
Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns; |
1881 |
Elf_Scn **scns = (Elf_Scn **) alloca (shnum * sizeof (Elf_Scn *)); |
1882 |
char *const shdr_start = ((char *) elf->map_address + elf->start_offset |
1883 |
@@ -571,6 +574,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf |
1884 |
/* Write all the sections. Well, only those which are modified. */ |
1885 |
if (shnum > 0) |
1886 |
{ |
1887 |
+ if (unlikely (shnum > SIZE_MAX / (sizeof (Elf_Scn *) |
1888 |
+ + sizeof (ElfW2(LIBELFBITS,Shdr))))) |
1889 |
+ return 1; |
1890 |
+ |
1891 |
off_t shdr_offset = elf->start_offset + ehdr->e_shoff; |
1892 |
#if EV_NUM != 2 |
1893 |
xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR]; |
1894 |
--- elfutils-0.127/libelf/gelf_getversym.c.robustify |
1895 |
+++ elfutils-0.127/libelf/gelf_getversym.c |
1896 |
@@ -92,7 +92,8 @@ gelf_getversym (data, ndx, dst) |
1897 |
|
1898 |
/* The data is already in the correct form. Just make sure the |
1899 |
index is OK. */ |
1900 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) |
1901 |
+ if (INVALID_NDX (ndx, GElf_Versym) |
1902 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) |
1903 |
{ |
1904 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1905 |
result = NULL; |
1906 |
--- elfutils-0.127/libelf/elf_getarsym.c.robustify |
1907 |
+++ elfutils-0.127/libelf/elf_getarsym.c |
1908 |
@@ -179,6 +179,9 @@ elf_getarsym (elf, ptr) |
1909 |
size_t index_size = atol (tmpbuf); |
1910 |
|
1911 |
if (SARMAG + sizeof (struct ar_hdr) + index_size > elf->maximum_size |
1912 |
+#if SIZE_MAX <= 4294967295U |
1913 |
+ || n >= SIZE_MAX / sizeof (Elf_Arsym) |
1914 |
+#endif |
1915 |
|| n * sizeof (uint32_t) > index_size) |
1916 |
{ |
1917 |
/* This index table cannot be right since it does not fit into |
1918 |
--- elfutils-0.127/libelf/gelf_getrel.c.robustify |
1919 |
+++ elfutils-0.127/libelf/gelf_getrel.c |
1920 |
@@ -71,12 +71,6 @@ gelf_getrel (data, ndx, dst) |
1921 |
if (data_scn == NULL) |
1922 |
return NULL; |
1923 |
|
1924 |
- if (unlikely (ndx < 0)) |
1925 |
- { |
1926 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1927 |
- return NULL; |
1928 |
- } |
1929 |
- |
1930 |
if (unlikely (data_scn->d.d_type != ELF_T_REL)) |
1931 |
{ |
1932 |
__libelf_seterrno (ELF_E_INVALID_HANDLE); |
1933 |
@@ -93,7 +87,8 @@ gelf_getrel (data, ndx, dst) |
1934 |
if (scn->elf->class == ELFCLASS32) |
1935 |
{ |
1936 |
/* We have to convert the data. */ |
1937 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) |
1938 |
+ if (INVALID_NDX (ndx, Elf32_Rel) |
1939 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) |
1940 |
{ |
1941 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1942 |
result = NULL; |
1943 |
@@ -113,7 +108,8 @@ gelf_getrel (data, ndx, dst) |
1944 |
{ |
1945 |
/* Simply copy the data after we made sure we are actually getting |
1946 |
correct data. */ |
1947 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) |
1948 |
+ if (INVALID_NDX (ndx, Elf64_Rel) |
1949 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) |
1950 |
{ |
1951 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1952 |
result = NULL; |
1953 |
--- elfutils-0.127/libelf/gelf_update_versym.c.robustify |
1954 |
+++ elfutils-0.127/libelf/gelf_update_versym.c |
1955 |
@@ -75,7 +75,7 @@ gelf_update_versym (data, ndx, src) |
1956 |
assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym)); |
1957 |
|
1958 |
/* Check whether we have to resize the data buffer. */ |
1959 |
- if (unlikely (ndx < 0) |
1960 |
+ if (INVALID_NDX (ndx, GElf_Versym) |
1961 |
|| unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size)) |
1962 |
{ |
1963 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1964 |
--- elfutils-0.127/libelf/gelf_getdyn.c.robustify |
1965 |
+++ elfutils-0.127/libelf/gelf_getdyn.c |
1966 |
@@ -93,7 +93,8 @@ gelf_getdyn (data, ndx, dst) |
1967 |
table entries has to be adopted. The user better has provided |
1968 |
a buffer where we can store the information. While copying the |
1969 |
data we are converting the format. */ |
1970 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) |
1971 |
+ if (INVALID_NDX (ndx, Elf32_Dyn) |
1972 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) |
1973 |
{ |
1974 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1975 |
goto out; |
1976 |
@@ -114,7 +115,8 @@ gelf_getdyn (data, ndx, dst) |
1977 |
|
1978 |
/* The data is already in the correct form. Just make sure the |
1979 |
index is OK. */ |
1980 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) |
1981 |
+ if (INVALID_NDX (ndx, GElf_Dyn) |
1982 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) |
1983 |
{ |
1984 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
1985 |
goto out; |
1986 |
--- elfutils-0.127/libelf/gelf_update_syminfo.c.robustify |
1987 |
+++ elfutils-0.127/libelf/gelf_update_syminfo.c |
1988 |
@@ -72,12 +72,6 @@ gelf_update_syminfo (data, ndx, src) |
1989 |
if (data == NULL) |
1990 |
return 0; |
1991 |
|
1992 |
- if (unlikely (ndx < 0)) |
1993 |
- { |
1994 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
1995 |
- return 0; |
1996 |
- } |
1997 |
- |
1998 |
if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO)) |
1999 |
{ |
2000 |
/* The type of the data better should match. */ |
2001 |
@@ -93,7 +87,8 @@ gelf_update_syminfo (data, ndx, src) |
2002 |
rwlock_wrlock (scn->elf->lock); |
2003 |
|
2004 |
/* Check whether we have to resize the data buffer. */ |
2005 |
- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) |
2006 |
+ if (INVALID_NDX (ndx, GElf_Syminfo) |
2007 |
+ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) |
2008 |
{ |
2009 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
2010 |
goto out; |
2011 |
--- elfutils-0.127/libelf/gelf_update_rel.c.robustify |
2012 |
+++ elfutils-0.127/libelf/gelf_update_rel.c |
2013 |
@@ -68,12 +68,6 @@ gelf_update_rel (Elf_Data *dst, int ndx, |
2014 |
if (dst == NULL) |
2015 |
return 0; |
2016 |
|
2017 |
- if (unlikely (ndx < 0)) |
2018 |
- { |
2019 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
2020 |
- return 0; |
2021 |
- } |
2022 |
- |
2023 |
if (unlikely (data_scn->d.d_type != ELF_T_REL)) |
2024 |
{ |
2025 |
/* The type of the data better should match. */ |
2026 |
@@ -99,7 +93,8 @@ gelf_update_rel (Elf_Data *dst, int ndx, |
2027 |
} |
2028 |
|
2029 |
/* Check whether we have to resize the data buffer. */ |
2030 |
- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) |
2031 |
+ if (INVALID_NDX (ndx, Elf32_Rel) |
2032 |
+ || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) |
2033 |
{ |
2034 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
2035 |
goto out; |
2036 |
@@ -114,7 +109,8 @@ gelf_update_rel (Elf_Data *dst, int ndx, |
2037 |
else |
2038 |
{ |
2039 |
/* Check whether we have to resize the data buffer. */ |
2040 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) |
2041 |
+ if (INVALID_NDX (ndx, Elf64_Rel) |
2042 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) |
2043 |
{ |
2044 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
2045 |
goto out; |
2046 |
--- elfutils-0.127/libelf/elf_newscn.c.robustify |
2047 |
+++ elfutils-0.127/libelf/elf_newscn.c |
2048 |
@@ -104,10 +104,18 @@ elf_newscn (elf) |
2049 |
else |
2050 |
{ |
2051 |
/* We must allocate a new element. */ |
2052 |
- Elf_ScnList *newp; |
2053 |
+ Elf_ScnList *newp = NULL; |
2054 |
|
2055 |
assert (elf->state.elf.scnincr > 0); |
2056 |
|
2057 |
+ if ( |
2058 |
+#if SIZE_MAX <= 4294967295U |
2059 |
+ likely (elf->state.elf.scnincr |
2060 |
+ < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList)) |
2061 |
+#else |
2062 |
+ 1 |
2063 |
+#endif |
2064 |
+ ) |
2065 |
newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList) |
2066 |
+ ((elf->state.elf.scnincr *= 2) |
2067 |
* sizeof (Elf_Scn)), 1); |
2068 |
--- elfutils-0.127/libelf/gelf_update_lib.c.robustify |
2069 |
+++ elfutils-0.127/libelf/gelf_update_lib.c |
2070 |
@@ -68,12 +68,6 @@ gelf_update_lib (data, ndx, src) |
2071 |
if (data == NULL) |
2072 |
return 0; |
2073 |
|
2074 |
- if (unlikely (ndx < 0)) |
2075 |
- { |
2076 |
- __libelf_seterrno (ELF_E_INVALID_INDEX); |
2077 |
- return 0; |
2078 |
- } |
2079 |
- |
2080 |
Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data; |
2081 |
if (unlikely (data_scn->d.d_type != ELF_T_LIB)) |
2082 |
{ |
2083 |
@@ -87,7 +81,8 @@ gelf_update_lib (data, ndx, src) |
2084 |
|
2085 |
/* Check whether we have to resize the data buffer. */ |
2086 |
int result = 0; |
2087 |
- if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) |
2088 |
+ if (INVALID_NDX (ndx, Elf64_Lib) |
2089 |
+ || unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) |
2090 |
__libelf_seterrno (ELF_E_INVALID_INDEX); |
2091 |
else |
2092 |
{ |
2093 |
--- elfutils-0.127/libelf/elf_getshstrndx.c.robustify |
2094 |
+++ elfutils-0.127/libelf/elf_getshstrndx.c |
2095 |
@@ -125,10 +125,25 @@ elf_getshstrndx (elf, dst) |
2096 |
if (elf->map_address != NULL |
2097 |
&& elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA |
2098 |
&& (ALLOW_UNALIGNED |
2099 |
- || (((size_t) ((char *) elf->map_address + offset)) |
2100 |
+ || (((size_t) ((char *) elf->map_address |
2101 |
+ + elf->start_offset + offset)) |
2102 |
& (__alignof__ (Elf32_Shdr) - 1)) == 0)) |
2103 |
+ { |
2104 |
+ /* First see whether the information in the ELF header is |
2105 |
+ valid and it does not ask for too much. */ |
2106 |
+ if (unlikely (offset + sizeof (Elf32_Shdr) |
2107 |
+ > elf->maximum_size)) |
2108 |
+ { |
2109 |
+ /* Something is wrong. */ |
2110 |
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); |
2111 |
+ result = -1; |
2112 |
+ goto out; |
2113 |
+ } |
2114 |
+ |
2115 |
/* We can directly access the memory. */ |
2116 |
- num = ((Elf32_Shdr *) (elf->map_address + offset))->sh_link; |
2117 |
+ num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset |
2118 |
+ + offset))->sh_link; |
2119 |
+ } |
2120 |
else |
2121 |
{ |
2122 |
/* We avoid reading in all the section headers. Just read |
2123 |
@@ -163,10 +178,25 @@ elf_getshstrndx (elf, dst) |
2124 |
if (elf->map_address != NULL |
2125 |
&& elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA |
2126 |
&& (ALLOW_UNALIGNED |
2127 |
- || (((size_t) ((char *) elf->map_address + offset)) |
2128 |
+ || (((size_t) ((char *) elf->map_address |
2129 |
+ + elf->start_offset + offset)) |
2130 |
& (__alignof__ (Elf64_Shdr) - 1)) == 0)) |
2131 |
+ { |
2132 |
+ /* First see whether the information in the ELF header is |
2133 |
+ valid and it does not ask for too much. */ |
2134 |
+ if (unlikely (offset + sizeof (Elf64_Shdr) |
2135 |
+ > elf->maximum_size)) |
2136 |
+ { |
2137 |
+ /* Something is wrong. */ |
2138 |
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); |
2139 |
+ result = -1; |
2140 |
+ goto out; |
2141 |
+ } |
2142 |
+ |
2143 |
/* We can directly access the memory. */ |
2144 |
- num = ((Elf64_Shdr *) (elf->map_address + offset))->sh_link; |
2145 |
+ num = ((Elf64_Shdr *) (elf->map_address |
2146 |
+ + elf->start_offset + offset))->sh_link; |
2147 |
+ } |
2148 |
else |
2149 |
{ |
2150 |
/* We avoid reading in all the section headers. Just read |
2151 |
--- elfutils-0.127/libelf/elf32_getshdr.c.robustify |
2152 |
+++ elfutils-0.127/libelf/elf32_getshdr.c |
2153 |
@@ -101,7 +101,8 @@ elfw2(LIBELFBITS,getshdr) (scn) |
2154 |
goto out; |
2155 |
|
2156 |
size_t shnum; |
2157 |
- if (INTUSE (elf_getshnum) (elf, &shnum) != 0) |
2158 |
+ if (INTUSE (elf_getshnum) (elf, &shnum) != 0 |
2159 |
+ || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr))) |
2160 |
goto out; |
2161 |
size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr)); |
2162 |
|
2163 |
@@ -118,6 +119,16 @@ elfw2(LIBELFBITS,getshdr) (scn) |
2164 |
|
2165 |
if (elf->map_address != NULL) |
2166 |
{ |
2167 |
+ /* First see whether the information in the ELF header is |
2168 |
+ valid and it does not ask for too much. */ |
2169 |
+ if (unlikely (ehdr->e_shoff >= elf->maximum_size) |
2170 |
+ || unlikely (ehdr->e_shoff + size > elf->maximum_size)) |
2171 |
+ { |
2172 |
+ /* Something is wrong. */ |
2173 |
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); |
2174 |
+ goto free_and_out; |
2175 |
+ } |
2176 |
+ |
2177 |
ElfW2(LIBELFBITS,Shdr) *notcvt; |
2178 |
|
2179 |
/* All the data is already mapped. If we could use it |
2180 |
--- elfutils-0.127/libelf/elf32_getphdr.c.robustify |
2181 |
+++ elfutils-0.127/libelf/elf32_getphdr.c |
2182 |
@@ -116,6 +116,16 @@ elfw2(LIBELFBITS,getphdr) (elf) |
2183 |
|
2184 |
if (elf->map_address != NULL) |
2185 |
{ |
2186 |
+ /* First see whether the information in the ELF header is |
2187 |
+ valid and it does not ask for too much. */ |
2188 |
+ if (unlikely (ehdr->e_phoff >= elf->maximum_size) |
2189 |
+ || unlikely (ehdr->e_phoff + size > elf->maximum_size)) |
2190 |
+ { |
2191 |
+ /* Something is wrong. */ |
2192 |
+ __libelf_seterrno (ELF_E_INVALID_PHDR); |
2193 |
+ goto out; |
2194 |
+ } |
2195 |
+ |
2196 |
/* All the data is already mapped. Use it. */ |
2197 |
void *file_phdr = ((char *) elf->map_address |
2198 |
+ elf->start_offset + ehdr->e_phoff); |
2199 |
|
2200 |
|
2201 |
|
2202 |
1.1 src/patchsets/elfutils/0.131/elfutils-strip-copy-symtab.patch |
2203 |
|
2204 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-strip-copy-symtab.patch?rev=1.1&view=markup |
2205 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/elfutils/0.131/elfutils-strip-copy-symtab.patch?rev=1.1&content-type=text/plain |
2206 |
|
2207 |
Index: elfutils-strip-copy-symtab.patch |
2208 |
=================================================================== |
2209 |
2006-09-19 Jakub Jelinek <jakub@××××××.com> |
2210 |
|
2211 |
* strip.c (handle_elf): Formatting. If any relocation sections |
2212 |
stripped into separate debug info reference symtab that is kept, |
2213 |
emit symtab/strtab also into the separate debug info file. |
2214 |
|
2215 |
--- elfutils/src/strip.c |
2216 |
+++ elfutils/src/strip.c |
2217 |
@@ -399,6 +399,7 @@ handle_elf (int fd, Elf *elf, const char |
2218 |
Elf_Scn *newscn; |
2219 |
struct Ebl_Strent *se; |
2220 |
Elf32_Word *newsymidx; |
2221 |
+ void *debug_data; |
2222 |
} *shdr_info = NULL; |
2223 |
Elf_Scn *scn; |
2224 |
size_t cnt; |
2225 |
@@ -826,8 +827,39 @@ handle_elf (int fd, Elf *elf, const char |
2226 |
The ones that are not removed in the stripped file are SHT_NOBITS. */ |
2227 |
if (debug_fname != NULL) |
2228 |
{ |
2229 |
+ /* libbfd and apps using it don't cope with separate debuginfo objects |
2230 |
+ with relocation sections against SHT_NOBITS .symtab/.strtab |
2231 |
+ - libbfd isn't able to look up the .symtab/.strtab in the stripped |
2232 |
+ object instead. As a workaround, emit .symtab/.strtab in both |
2233 |
+ places. */ |
2234 |
for (cnt = 1; cnt < shnum; ++cnt) |
2235 |
{ |
2236 |
+ if (shdr_info[cnt].idx == 0 |
2237 |
+ && (shdr_info[cnt].shdr.sh_type == SHT_REL |
2238 |
+ || shdr_info[cnt].shdr.sh_type == SHT_RELA) |
2239 |
+ && (shdr_info[cnt].shdr.sh_flags & SHF_ALLOC) == 0) |
2240 |
+ { |
2241 |
+ Elf32_Word symtabidx = shdr_info[cnt].old_sh_link; |
2242 |
+ struct shdr_info *si = &shdr_info[symtabidx]; |
2243 |
+ si->debug_data = ""; |
2244 |
+ shdr_info[si->old_sh_link].debug_data = ""; |
2245 |
+ if (si->symtab_idx) |
2246 |
+ shdr_info[si->symtab_idx].debug_data = ""; |
2247 |
+ |
2248 |
+ if (si->shdr.sh_type != SHT_SYMTAB |
2249 |
+ || (si->shdr.sh_flags & SHF_ALLOC) |
2250 |
+ || shdr_info[si->old_sh_link].shdr.sh_type != SHT_STRTAB |
2251 |
+ || (shdr_info[si->old_sh_link].shdr.sh_flags & SHF_ALLOC) |
2252 |
+ || (si->symtab_idx |
2253 |
+ && (shdr_info[si->symtab_idx].shdr.sh_flags |
2254 |
+ & SHF_ALLOC))) |
2255 |
+ error (EXIT_FAILURE, 0, |
2256 |
+ gettext ("invalid symtab/strtab referenced by nonallocated section")); |
2257 |
+ } |
2258 |
+ } |
2259 |
+ |
2260 |
+ for (cnt = 1; cnt < shnum; ++cnt) |
2261 |
+ { |
2262 |
scn = elf_newscn (debugelf); |
2263 |
if (scn == NULL) |
2264 |
error (EXIT_FAILURE, 0, |
2265 |
@@ -835,8 +867,9 @@ handle_elf (int fd, Elf *elf, const char |
2266 |
elf_errmsg (-1)); |
2267 |
|
2268 |
bool discard_section = (shdr_info[cnt].idx > 0 |
2269 |
&& shdr_info[cnt].shdr.sh_type != SHT_NOTE |
2270 |
- && cnt != ehdr->e_shstrndx); |
2271 |
+ && cnt != ehdr->e_shstrndx |
2272 |
+ && shdr_info[cnt].debug_data == NULL); |
2273 |
|
2274 |
/* Set the section header in the new file. */ |
2275 |
GElf_Shdr debugshdr = shdr_info[cnt].shdr; |
2276 |
@@ -864,6 +897,13 @@ handle_elf (int fd, Elf *elf, const char |
2277 |
*debugdata = *shdr_info[cnt].data; |
2278 |
if (discard_section) |
2279 |
debugdata->d_buf = NULL; |
2280 |
+ else if (shdr_info[cnt].debug_data != NULL) |
2281 |
+ { |
2282 |
+ shdr_info[cnt].debug_data = xmalloc (debugdata->d_size); |
2283 |
+ memcpy (shdr_info[cnt].debug_data, debugdata->d_buf, |
2284 |
+ debugdata->d_size); |
2285 |
+ debugdata->d_buf = shdr_info[cnt].debug_data; |
2286 |
+ } |
2287 |
} |
2288 |
|
2289 |
/* Finish the ELF header. Fill in the fields not handled by |
2290 |
@@ -1055,7 +1095,7 @@ handle_elf (int fd, Elf *elf, const char |
2291 |
shdr_info[shdr_info[cnt].shdr.sh_info].idx; |
2292 |
|
2293 |
/* Get the data from the old file if necessary. We already |
2294 |
- created the data for the section header string table. */ |
2295 |
+ created the data for the section header string table. */ |
2296 |
if (cnt < shnum) |
2297 |
{ |
2298 |
if (shdr_info[cnt].data == NULL) |
2299 |
@@ -1264,6 +1304,13 @@ handle_elf (int fd, Elf *elf, const char |
2300 |
if (shdr_info[shdr_info[cnt].old_sh_link].newsymidx == NULL) |
2301 |
continue; |
2302 |
|
2303 |
+ /* If the symbol table is not discarded, but additionally |
2304 |
+ duplicated in separate debug file and this section |
2305 |
+ is discarded, don't adjust anything. */ |
2306 |
+ if (shdr_info[cnt].idx == 0 |
2307 |
+ && shdr_info[shdr_info[cnt].old_sh_link].debug_data != NULL) |
2308 |
+ continue; |
2309 |
+ |
2310 |
Elf32_Word *newsymidx |
2311 |
= shdr_info[shdr_info[cnt].old_sh_link].newsymidx; |
2312 |
Elf_Data *d = elf_getdata (shdr_info[cnt].idx == 0 |
2313 |
@@ -1322,6 +1369,13 @@ handle_elf (int fd, Elf *elf, const char |
2314 |
if (shdr_info[symtabidx].newsymidx == NULL) |
2315 |
continue; |
2316 |
|
2317 |
+ /* If the symbol table is not discarded, but additionally |
2318 |
+ duplicated in separate debug file and this section |
2319 |
+ is discarded, don't adjust anything. */ |
2320 |
+ if (shdr_info[cnt].idx == 0 |
2321 |
+ && shdr_info[symtabidx].debug_data != NULL) |
2322 |
+ continue; |
2323 |
+ |
2324 |
assert (shdr_info[cnt].idx > 0); |
2325 |
|
2326 |
/* The hash section in the new file. */ |
2327 |
@@ -1447,7 +1501,7 @@ handle_elf (int fd, Elf *elf, const char |
2328 |
chain[hidx] = inner; |
2329 |
} |
2330 |
} |
2331 |
- } |
2332 |
+ } |
2333 |
} |
2334 |
else if (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym) |
2335 |
{ |
2336 |
@@ -1460,6 +1514,13 @@ handle_elf (int fd, Elf *elf, const char |
2337 |
if (shdr_info[symtabidx].newsymidx == NULL) |
2338 |
continue; |
2339 |
|
2340 |
+ /* If the symbol table is not discarded, but additionally |
2341 |
+ duplicated in separate debug file and this section |
2342 |
+ is discarded, don't adjust anything. */ |
2343 |
+ if (shdr_info[cnt].idx == 0 |
2344 |
+ && shdr_info[symtabidx].debug_data != NULL) |
2345 |
+ continue; |
2346 |
+ |
2347 |
assert (shdr_info[cnt].idx > 0); |
2348 |
|
2349 |
/* The symbol version section in the new file. */ |
2350 |
@@ -1504,20 +1565,27 @@ handle_elf (int fd, Elf *elf, const char |
2351 |
else if (shdr_info[cnt].shdr.sh_type == SHT_GROUP) |
2352 |
{ |
2353 |
/* Check whether the associated symbol table changed. */ |
2354 |
- if (shdr_info[shdr_info[cnt].old_sh_link].newsymidx != NULL) |
2355 |
- { |
2356 |
- /* Yes the symbol table changed. Update the section |
2357 |
- header of the section group. */ |
2358 |
- scn = elf_getscn (newelf, shdr_info[cnt].idx); |
2359 |
- GElf_Shdr shdr_mem; |
2360 |
- GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); |
2361 |
- assert (shdr != NULL); |
2362 |
+ if (shdr_info[shdr_info[cnt].old_sh_link].newsymidx == NULL) |
2363 |
+ continue; |
2364 |
|
2365 |
- size_t stabidx = shdr_info[cnt].old_sh_link; |
2366 |
- shdr->sh_info = shdr_info[stabidx].newsymidx[shdr->sh_info]; |
2367 |
+ /* If the symbol table is not discarded, but additionally |
2368 |
+ duplicated in separate debug file and this section |
2369 |
+ is discarded, don't adjust anything. */ |
2370 |
+ if (shdr_info[cnt].idx == 0 |
2371 |
+ && shdr_info[shdr_info[cnt].old_sh_link].debug_data != NULL) |
2372 |
+ continue; |
2373 |
|
2374 |
- (void) gelf_update_shdr (scn, shdr); |
2375 |
- } |
2376 |
+ /* Yes the symbol table changed. Update the section |
2377 |
+ header of the section group. */ |
2378 |
+ scn = elf_getscn (newelf, shdr_info[cnt].idx); |
2379 |
+ GElf_Shdr shdr_mem; |
2380 |
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); |
2381 |
+ assert (shdr != NULL); |
2382 |
+ |
2383 |
+ size_t stabidx = shdr_info[cnt].old_sh_link; |
2384 |
+ shdr->sh_info = shdr_info[stabidx].newsymidx[shdr->sh_info]; |
2385 |
+ |
2386 |
+ (void) gelf_update_shdr (scn, shdr); |
2387 |
} |
2388 |
} |
2389 |
} |
2390 |
@@ -1647,7 +1715,10 @@ handle_elf (int fd, Elf *elf, const char |
2391 |
table indices. */ |
2392 |
if (any_symtab_changes) |
2393 |
for (cnt = 1; cnt <= shdridx; ++cnt) |
2394 |
- free (shdr_info[cnt].newsymidx); |
2395 |
+ { |
2396 |
+ free (shdr_info[cnt].newsymidx); |
2397 |
+ free (shdr_info[cnt].debug_data); |
2398 |
+ } |
2399 |
|
2400 |
/* Free the memory. */ |
2401 |
if ((shnum + 2) * sizeof (struct shdr_info) > MAX_STACK_ALLOC) |
2402 |
|
2403 |
--- elfutils-0.124/tests/run-strip-test5.sh.~1~ |
2404 |
+++ elfutils-0.124/tests/run-strip-test5.sh |
2405 |
@@ -1,5 +1,5 @@ |
2406 |
original=testfile8 |
2407 |
-stripped=testfile16 |
2408 |
-debugfile=testfile16.debug |
2409 |
+stripped=testfile16.symtab |
2410 |
+debugfile=testfile16.symtab.debug |
2411 |
|
2412 |
. $srcdir/run-strip-test.sh |
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
-- |
2418 |
gentoo-commits@g.o mailing list |