From 840723d31652a1bad2cead0def4163d783d05374 Mon Sep 17 00:00:00 2001 From: roland Date: Tue, 22 Jan 2008 01:09:23 +0000 Subject: [PATCH] New upstream version 0.132 --- .cvsignore | 2 +- elfutils-portability.patch | 194 ++-- elfutils-robustify.patch | 2171 ++++++++++++++++++------------------ elfutils.spec | 11 +- sources | 2 +- 5 files changed, 1185 insertions(+), 1195 deletions(-) diff --git a/.cvsignore b/.cvsignore index 1a2e9f4..847ddaa 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,3 +1,3 @@ testfile16.symtab.bz2 testfile16.symtab.debug.bz2 -elfutils-0.131.tar.gz +elfutils-0.132.tar.gz diff --git a/elfutils-portability.patch b/elfutils-portability.patch index 737e099..81a8adb 100644 --- a/elfutils-portability.patch +++ b/elfutils-portability.patch @@ -1,6 +1,6 @@ --- elfutils/backends/ChangeLog +++ elfutils/backends/ChangeLog -@@ -240,6 +240,11 @@ +@@ -258,6 +258,11 @@ * sparc_init.c: Likewise. * x86_64_init.c: Likewise. @@ -12,7 +12,7 @@ 2005-11-19 Roland McGrath * ppc64_reloc.def: REL30 -> ADDR30. -@@ -262,6 +267,9 @@ +@@ -280,6 +285,9 @@ * Makefile.am (uninstall): Don't try to remove $(pkgincludedir). (CLEANFILES): Add libebl_$(m).so. @@ -38,20 +38,19 @@ -AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused -Wextra -Wformat=2 \ +AM_CFLAGS += -fpic -Wall -Wshadow -Werror -Wunused $(WEXTRA) -Wformat=2 \ -std=gnu99 - INCLUDES = -I$(srcdir) -I$(top_srcdir)/libebl \ + INCLUDES = -I$(srcdir) -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \ -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ -@@ -62,7 +64,7 @@ textrel_check = if readelf -d $@ | fgrep - libebl_%.so: libebl_%_pic.a libebl_%.map $(libelf) $(libdw) - $(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ - -Wl,--version-script,$(word 2,$^) \ -- -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libmudflap) -+ -Wl,-z,defs $(LD_AS_NEEDED) $(libelf) $(libdw) $(libmudflap) - $(textrel_check) +@@ -59,7 +61,6 @@ endif - libebl_%.map: Makefile + textrel_check = if readelf -d $@ | fgrep -q TEXTREL; then exit 1; fi + +- + i386_SRCS = i386_init.c i386_symbol.c i386_corenote.c \ + i386_retval.c i386_regs.c i386_auxv.c + cpu_i386 = ../libcpu/libcpu_i386.a --- elfutils/backends/Makefile.in +++ elfutils/backends/Makefile.in -@@ -152,6 +152,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -153,6 +153,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -59,7 +58,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -181,6 +182,7 @@ SHELL = @SHELL@ +@@ -182,6 +183,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -67,7 +66,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -236,9 +238,9 @@ target_alias = @target_alias@ +@@ -237,9 +239,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -fpic -Wall -Wshadow -Werror -Wunused \ @@ -76,21 +75,12 @@ @MUDFLAP_TRUE@AM_CFLAGS = -fmudflap -fpic -Wall -Wshadow -Werror \ -@MUDFLAP_TRUE@ -Wunused -Wextra -Wformat=2 -std=gnu99 +@MUDFLAP_TRUE@ -Wunused $(WEXTRA) -Wformat=2 -std=gnu99 - INCLUDES = -I$(srcdir) -I$(top_srcdir)/libebl \ + INCLUDES = -I$(srcdir) -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \ -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ -I$(top_srcdir)/lib -I.. -@@ -626,7 +628,7 @@ uninstall-am: - libebl_%.so: libebl_%_pic.a libebl_%.map $(libelf) $(libdw) - $(LINK) -shared -o $@ -Wl,--whole-archive,$<,--no-whole-archive \ - -Wl,--version-script,$(word 2,$^) \ -- -Wl,-z,defs -Wl,--as-needed $(libelf) $(libdw) $(libmudflap) -+ -Wl,-z,defs $(LD_AS_NEEDED) $(libelf) $(libdw) $(libmudflap) - $(textrel_check) - - libebl_%.map: Makefile --- elfutils/ChangeLog +++ elfutils/ChangeLog -@@ -25,6 +25,10 @@ +@@ -30,6 +30,10 @@ * configure.ac: Add dummy automake conditional to get dependencies for non-generic linker right. See src/Makefile.am. @@ -101,7 +91,7 @@ 2005-11-18 Roland McGrath * Makefile.am (DISTCHECK_CONFIGURE_FLAGS): New variable. -@@ -72,6 +76,17 @@ +@@ -77,6 +81,17 @@ * Makefile.am (all_SUBDIRS): Add libdwfl. * configure.ac: Write libdwfl/Makefile. @@ -121,7 +111,7 @@ * configure.ac [AH_BOTTOM] (INTDECL, _INTDECL): New macros. --- elfutils/config/Makefile.in +++ elfutils/config/Makefile.in -@@ -71,6 +71,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -72,6 +72,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -129,7 +119,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -100,6 +101,7 @@ SHELL = @SHELL@ +@@ -101,6 +102,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -148,7 +138,7 @@ LOCALEDIR DATADIRNAME NATIVE_LD_TRUE -@@ -3874,6 +3876,88 @@ echo "$as_me: error: gcc with C99 suppor +@@ -3877,6 +3879,88 @@ echo "$as_me: error: gcc with C99 suppor fi @@ -237,7 +227,7 @@ LOCALEDIR=$datadir cat >>confdefs.h <<_ACEOF -@@ -5608,10 +5692,10 @@ YFLAGS!$YFLAGS$ac_delim +@@ -5621,10 +5705,10 @@ YFLAGS!$YFLAGS$ac_delim LEX!$LEX$ac_delim LEX_OUTPUT_ROOT!$LEX_OUTPUT_ROOT$ac_delim LEXLIB!$LEXLIB$ac_delim @@ -250,7 +240,7 @@ _ACEOF if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then -@@ -5653,6 +5737,8 @@ _ACEOF +@@ -5666,6 +5750,8 @@ _ACEOF ac_delim='%!_!# ' for ac_last_try in false false false false false :; do cat >conf$$subs.sed <<_ACEOF @@ -259,12 +249,12 @@ base_cpu!$base_cpu$ac_delim NEVER_TRUE!$NEVER_TRUE$ac_delim NEVER_FALSE!$NEVER_FALSE$ac_delim -@@ -5683,7 +5769,7 @@ LIBOBJS!$LIBOBJS$ac_delim +@@ -5697,7 +5783,7 @@ LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF -- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 28; then -+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 30; then +- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 29; then ++ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 31; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 @@ -338,7 +328,7 @@ noinst_LIBRARIES = libeu.a --- elfutils/lib/Makefile.in +++ elfutils/lib/Makefile.in -@@ -91,6 +91,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -92,6 +92,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -346,7 +336,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -120,6 +121,7 @@ SHELL = @SHELL@ +@@ -121,6 +122,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -354,7 +344,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -175,9 +177,9 @@ target_alias = @target_alias@ +@@ -176,9 +178,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -fpic -Wall -Wshadow -Werror -Wunused \ @@ -368,7 +358,7 @@ libeu_a_SOURCES = xstrndup.c xmalloc.c next_prime.c \ --- elfutils/libasm/ChangeLog +++ elfutils/libasm/ChangeLog -@@ -32,6 +32,11 @@ +@@ -54,6 +54,11 @@ * asm_error.c: Add new error ASM_E_IOERROR. * libasmP.h: Add ASM_E_IOERROR definition. @@ -399,7 +389,7 @@ -I$(top_srcdir)/lib --- elfutils/libasm/Makefile.in +++ elfutils/libasm/Makefile.in -@@ -124,6 +124,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -126,6 +126,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -407,7 +397,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -153,6 +154,7 @@ SHELL = @SHELL@ +@@ -155,6 +156,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = 1 @@ -415,7 +405,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -208,9 +210,9 @@ target_alias = @target_alias@ +@@ -210,9 +212,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Werror -Wunused \ @@ -429,7 +419,10 @@ -I$(top_srcdir)/lib --- elfutils/libcpu/ChangeLog +++ elfutils/libcpu/ChangeLog -@@ -1,3 +1,8 @@ +@@ -260,6 +260,11 @@ + * defs/i386.doc: New file. + * defs/x86_64: New file. + +2005-04-04 Roland McGrath + + * Makefile.am (WEXTRA): New variable, substituted by configure. @@ -440,27 +433,27 @@ * Makefile (AM_CFLAGS): Add -Wunused -Wextra -Wformat=2. --- elfutils/libcpu/Makefile.am +++ elfutils/libcpu/Makefile.am -@@ -25,7 +25,8 @@ - ## . - ## - DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H --AM_CFLAGS = -Wall -Wshadow -Werror -Wextra -Wformat=2 -Wunused +@@ -30,7 +30,8 @@ AM_CFLAGS = -fmudflap + else + AM_CFLAGS = + endif +-AM_CFLAGS += -Wall -Wshadow -Wunused -Wextra -std=gnu99 -fpic \ +WEXTRA = @WEXTRA@ -+AM_CFLAGS = -Wall -Wshadow -Werror $(WEXTRA) -Wformat=2 -Wunused - INCLUDES = -I$(srcdir) - - noinst_LIBRARIES = libcpu_i386.a ++AM_CFLAGS += -Wall -Wshadow -Wunused $(WEXTRA) -std=gnu99 -fpic \ + $($(*F)_CFLAGS) \ + $(if $($(*F)_no_Werror),,-Werror) + INCLUDES = -I$(srcdir) -I$(srcdir)/../lib -I$(srcdir)/../libelf \ --- elfutils/libcpu/Makefile.in +++ elfutils/libcpu/Makefile.in -@@ -87,6 +87,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -109,6 +109,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ +LD_AS_NEEDED = @LD_AS_NEEDED@ LEX = @LEX@ LEXLIB = @LEXLIB@ - LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -116,6 +117,7 @@ SHELL = @SHELL@ + LEX_OUTPUT_ROOT = lex.$( @@ -512,7 +510,7 @@ --- elfutils/libdw/Makefile.in +++ elfutils/libdw/Makefile.in -@@ -163,6 +163,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -164,6 +164,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -520,7 +518,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -192,6 +193,7 @@ SHELL = @SHELL@ +@@ -193,6 +194,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = 1 @@ -528,7 +526,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -247,9 +249,10 @@ target_alias = @target_alias@ +@@ -248,9 +250,10 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = $(am__append_1) -Wall -Werror -Wshadow \ @@ -543,7 +541,7 @@ $(COMPILE))) --- elfutils/libdwfl/ChangeLog +++ elfutils/libdwfl/ChangeLog -@@ -739,6 +739,11 @@ +@@ -744,6 +744,11 @@ 2005-07-21 Roland McGrath @@ -574,7 +572,7 @@ VERSION = 1 --- elfutils/libdwfl/Makefile.in +++ elfutils/libdwfl/Makefile.in -@@ -128,6 +128,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -129,6 +129,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -582,7 +580,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -157,6 +158,7 @@ SHELL = @SHELL@ +@@ -158,6 +159,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = 1 @@ -590,7 +588,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -212,9 +214,9 @@ target_alias = @target_alias@ +@@ -213,9 +215,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -Wall -Werror -Wshadow -Wunused -Wformat=2 \ @@ -635,7 +633,7 @@ INCLUDES = -I$(srcdir) -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ --- elfutils/libebl/Makefile.in +++ elfutils/libebl/Makefile.in -@@ -120,6 +120,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -121,6 +121,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -643,7 +641,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -149,6 +150,7 @@ SHELL = @SHELL@ +@@ -150,6 +151,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = 1 @@ -651,7 +649,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -204,9 +206,9 @@ target_alias = @target_alias@ +@@ -205,9 +207,9 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -fpic -Wall -Wshadow -Werror -Wunused \ @@ -661,11 +659,11 @@ -@MUDFLAP_TRUE@ -Wunused -Wextra -Wformat=2 -std=gnu99 +@MUDFLAP_TRUE@ -Wunused $(WEXTRA) -Wformat=2 -std=gnu99 INCLUDES = -I$(srcdir) -I$(top_srcdir)/libelf -I$(top_srcdir)/libdw \ - -I$(top_srcdir)/lib -I.. + -I$(top_srcdir)/lib -I.. -I$(srcdir)/../libasm --- elfutils/libelf/ChangeLog +++ elfutils/libelf/ChangeLog -@@ -303,6 +303,11 @@ +@@ -333,6 +333,11 @@ If section content hasn't been read yet, do it before looking for the block size. If no section data present, infer size of section header. @@ -679,7 +677,7 @@ * elf.h: Update again. --- elfutils/libelf/common.h +++ elfutils/libelf/common.h -@@ -155,7 +155,7 @@ libelf_release_all (Elf *elf) +@@ -159,7 +159,7 @@ libelf_release_all (Elf *elf) (Var) = (sizeof (Var) == 1 \ ? (unsigned char) (Var) \ : (sizeof (Var) == 2 \ @@ -688,7 +686,7 @@ : (sizeof (Var) == 4 \ ? bswap_32 (Var) \ : bswap_64 (Var)))) -@@ -164,7 +164,7 @@ libelf_release_all (Elf *elf) +@@ -168,7 +168,7 @@ libelf_release_all (Elf *elf) (Dst) = (sizeof (Var) == 1 \ ? (unsigned char) (Var) \ : (sizeof (Var) == 2 \ @@ -730,7 +728,7 @@ @MUDFLAP_FALSE@noinst_PROGRAMS = $(am__EXEEXT_1) @MUDFLAP_TRUE@am_libelf_pic_a_OBJECTS = subdir = libelf -@@ -168,6 +168,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -170,6 +170,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -738,7 +736,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -197,6 +198,7 @@ SHELL = @SHELL@ +@@ -199,6 +200,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = 1 @@ -746,7 +744,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -252,10 +254,10 @@ target_alias = @target_alias@ +@@ -254,10 +256,10 @@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = $(am__append_1) -Wall -Wshadow -Werror \ @@ -761,7 +759,7 @@ GCC_INCLUDE = -I$(shell $(CC) -print-file-name=include) --- elfutils/m4/Makefile.in +++ elfutils/m4/Makefile.in -@@ -70,6 +70,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -71,6 +71,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -769,7 +767,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -99,6 +100,7 @@ SHELL = @SHELL@ +@@ -100,6 +101,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -779,7 +777,7 @@ YACC = @YACC@ --- elfutils/Makefile.in +++ elfutils/Makefile.in -@@ -97,6 +97,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -98,6 +98,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -787,7 +785,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -126,6 +127,7 @@ SHELL = @SHELL@ +@@ -127,6 +128,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -797,7 +795,7 @@ YACC = @YACC@ --- elfutils/src/ChangeLog +++ elfutils/src/ChangeLog -@@ -30,6 +30,8 @@ +@@ -126,6 +126,8 @@ * readelf.c (hex_dump): Fix rounding error in whitespace calculation. @@ -806,7 +804,7 @@ 2007-10-15 Roland McGrath * make-debug-archive.in: New file. -@@ -469,6 +471,10 @@ +@@ -565,6 +567,10 @@ * elflint.c (valid_e_machine): Add EM_ALPHA. Reported by Christian Aichinger . @@ -817,7 +815,7 @@ 2006-08-08 Ulrich Drepper * elflint.c (check_dynamic): Don't require DT_HASH for DT_SYMTAB. -@@ -545,6 +551,10 @@ +@@ -641,6 +647,10 @@ * Makefile.am: Add hacks to create dependency files for non-generic linker. @@ -828,7 +826,7 @@ 2006-06-12 Ulrich Drepper * ldgeneric.c (ld_generic_generate_sections): Don't create .interp -@@ -893,6 +903,11 @@ +@@ -989,6 +999,11 @@ * readelf.c (print_debug_loc_section): Fix indentation for larger address size. @@ -859,7 +857,7 @@ +++ elfutils/src/Makefile.am @@ -26,6 +26,7 @@ ## - DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H $(YYDEBUG) \ + DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H $(YYDEBUG) -DDEBUGPRED=@DEBUGPRED@ \ -DSRCDIR=\"$(shell cd $(srcdir);pwd)\" -DOBJDIR=\"$(shell pwd)\" +WEXTRA = @WEXTRA@ if MUDFLAP @@ -874,7 +872,7 @@ $(if $($(*F)_no_Wformat),,-Wformat=2) $(CFLAGS_$(*F)) INCLUDES = -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ -@@ -108,6 +109,9 @@ strings_no_Wformat = yes +@@ -111,6 +112,9 @@ strings_no_Wformat = yes # XXX While the file is not finished, don't warn about this ldgeneric_no_Wunused = yes @@ -886,7 +884,7 @@ size_LDADD = $(libelf) $(libeu) $(libmudflap) --- elfutils/src/Makefile.in +++ elfutils/src/Makefile.in -@@ -200,6 +200,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -201,6 +201,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -894,7 +892,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -229,6 +230,7 @@ SHELL = @SHELL@ +@@ -230,6 +231,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -902,7 +900,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -d -@@ -286,13 +288,13 @@ top_srcdir = @top_srcdir@ +@@ -287,13 +289,13 @@ top_srcdir = @top_srcdir@ @MUDFLAP_FALSE@AM_CFLAGS = -Wall -Wshadow -std=gnu99 \ @MUDFLAP_FALSE@ $(native_ld_cflags) $(if \ @MUDFLAP_FALSE@ $($(*F)_no_Werror),,-Werror) $(if \ @@ -918,7 +916,7 @@ @MUDFLAP_TRUE@ $($(*F)_no_Wformat),,-Wformat=2) $(CFLAGS_$(*F)) INCLUDES = -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \ -I$(srcdir)/../libdw -I$(srcdir)/../libdwfl \ -@@ -334,6 +336,9 @@ size_no_Wformat = yes +@@ -337,6 +339,9 @@ size_no_Wformat = yes strings_no_Wformat = yes # XXX While the file is not finished, don't warn about this ldgeneric_no_Wunused = yes @@ -989,7 +987,7 @@ } /* Open the file. */ -@@ -1702,7 +1718,7 @@ handle_elf (int fd, Elf *elf, const char +@@ -1703,7 +1719,7 @@ handle_elf (int fd, Elf *elf, const char /* If requested, preserve the timestamp. */ if (tvp != NULL) { @@ -998,7 +996,7 @@ { error (0, errno, gettext ("\ cannot set access and modification date of '%s'"), -@@ -1759,7 +1775,7 @@ handle_ar (int fd, Elf *elf, const char +@@ -1760,7 +1776,7 @@ handle_ar (int fd, Elf *elf, const char if (tvp != NULL) { @@ -1009,7 +1007,7 @@ cannot set access and modification date of '%s'"), fname); --- elfutils/tests/ChangeLog +++ elfutils/tests/ChangeLog -@@ -606,6 +606,11 @@ +@@ -703,6 +703,11 @@ * Makefile.am (TESTS): Add run-elflint-test.sh. (EXTRA_DIST): Add run-elflint-test.sh and testfile18.bz2. @@ -1041,7 +1039,7 @@ endif --- elfutils/tests/Makefile.in +++ elfutils/tests/Makefile.in -@@ -323,6 +323,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ +@@ -325,6 +325,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LDFLAGS = @LDFLAGS@ @@ -1049,7 +1047,7 @@ LEX = @LEX@ LEXLIB = @LEXLIB@ LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -@@ -352,6 +353,7 @@ SHELL = @SHELL@ +@@ -354,6 +355,7 @@ SHELL = @SHELL@ STRIP = @STRIP@ USE_NLS = @USE_NLS@ VERSION = @VERSION@ @@ -1057,7 +1055,7 @@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ YACC = @YACC@ -@@ -406,10 +408,10 @@ sysconfdir = @sysconfdir@ +@@ -408,10 +410,10 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ diff --git a/elfutils-robustify.patch b/elfutils-robustify.patch index ddeebce..7bc2a35 100644 --- a/elfutils-robustify.patch +++ b/elfutils-robustify.patch @@ -65,489 +65,8 @@ src/ (check_symtab, is_rel_dyn, check_rela, check_rel, check_dynamic, check_symtab_shndx, check_hash, check_versym): Robustify. ---- elfutils-0.130/src/readelf.c.robustify -+++ elfutils-0.130/src/readelf.c -@@ -1053,6 +1053,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G - Elf32_Word *grpref = (Elf32_Word *) data->d_buf; - - GElf_Sym sym_mem; -+ GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem); -+ - printf ((grpref[0] & GRP_COMDAT) - ? ngettext ("\ - \nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n", -@@ -1065,8 +1067,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G - data->d_size / sizeof (Elf32_Word) - 1), - elf_ndxscn (scn), - elf_strptr (ebl->elf, shstrndx, shdr->sh_name), -- elf_strptr (ebl->elf, symshdr->sh_link, -- gelf_getsym (symdata, shdr->sh_info, &sym_mem)->st_name) -+ (sym == NULL ? NULL -+ : elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)) - ?: gettext (""), - data->d_size / sizeof (Elf32_Word) - 1); - -@@ -1217,7 +1219,8 @@ static void - handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) - { - int class = gelf_getclass (ebl->elf); -- GElf_Shdr glink; -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink; - Elf_Data *data; - size_t cnt; - size_t shstrndx; -@@ -1232,6 +1235,11 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, - error (EXIT_FAILURE, 0, - gettext ("cannot get section header string table index")); - -+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); -+ if (glink == NULL) -+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ - printf (ngettext ("\ - \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", - "\ -@@ -1241,9 +1249,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, - class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, - shdr->sh_offset, - (int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - fputs_unlocked (gettext (" Type Value\n"), stdout); - - for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) -@@ -1761,6 +1767,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G - error (EXIT_FAILURE, 0, - gettext ("cannot get section header string table index")); - -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -+ &glink_mem); -+ if (glink == NULL) -+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ - /* Now we can compute the number of entries in the section. */ - unsigned int nsyms = data->d_size / (class == ELFCLASS32 - ? sizeof (Elf32_Sym) -@@ -1771,15 +1784,12 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G - nsyms), - (unsigned int) elf_ndxscn (scn), - elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms); -- GElf_Shdr glink; - printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n", - " %lu local symbols String table: [%2u] '%s'\n", - shdr->sh_info), - (unsigned long int) shdr->sh_info, - (unsigned int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - - fputs_unlocked (class == ELFCLASS32 - ? gettext ("\ -@@ -2015,7 +2025,13 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, - error (EXIT_FAILURE, 0, - gettext ("cannot get section header string table index")); - -- GElf_Shdr glink; -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -+ &glink_mem); -+ if (glink == NULL) -+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ - printf (ngettext ("\ - \nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", - "\ -@@ -2026,9 +2042,7 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, - class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, - shdr->sh_offset, - (unsigned int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - - unsigned int offset = 0; - for (int cnt = shdr->sh_info; --cnt >= 0; ) -@@ -2081,8 +2095,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G - error (EXIT_FAILURE, 0, - gettext ("cannot get section header string table index")); - -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -+ &glink_mem); -+ if (glink == NULL) -+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ - int class = gelf_getclass (ebl->elf); -- GElf_Shdr glink; - printf (ngettext ("\ - \nVersion definition section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", - "\ -@@ -2094,9 +2114,7 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G - class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, - shdr->sh_offset, - (unsigned int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - - unsigned int offset = 0; - for (int cnt = shdr->sh_info; --cnt >= 0; ) -@@ -2358,8 +2376,14 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G - filename = NULL; - } - -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -+ &glink_mem); -+ if (glink == NULL) -+ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ - /* Print the header. */ -- GElf_Shdr glink; - printf (ngettext ("\ - \nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'", - "\ -@@ -2371,9 +2395,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G - class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, - shdr->sh_offset, - (unsigned int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - - /* Now we can finally look at the actual contents of this section. */ - for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) -@@ -2425,7 +2447,17 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, - for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt) - ++counts[lengths[cnt]]; - -- GElf_Shdr glink; -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, -+ shdr->sh_link), -+ &glink_mem); -+ if (glink == NULL) -+ { -+ error (0, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ return; -+ } -+ - printf (ngettext ("\ - \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", - "\ -@@ -2438,9 +2470,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, - shdr->sh_addr, - shdr->sh_offset, - (unsigned int) shdr->sh_link, -- elf_strptr (ebl->elf, shstrndx, -- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), -- &glink)->sh_name)); -+ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); - - if (extrastr != NULL) - fputs (extrastr, stdout); -@@ -3834,6 +3864,16 @@ print_debug_aranges_section (Dwfl_Module - return; - } - -+ GElf_Shdr glink_mem; -+ GElf_Shdr *glink; -+ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); -+ if (glink == NULL) -+ { -+ error (0, 0, gettext ("invalid sh_link value in section %Zu"), -+ elf_ndxscn (scn)); -+ return; -+ } -+ - printf (ngettext ("\ - \nDWARF section '%s' at offset %#" PRIx64 " contains %zu entry:\n", - "\ ---- elfutils-0.128/src/strip.c.orig -+++ elfutils-0.128/src/strip.c -@@ -413,6 +413,7 @@ handle_elf (int fd, Elf *elf, const char - Elf_Data debuglink_crc_data; - bool any_symtab_changes = false; - Elf_Data *shstrtab_data = NULL; -+ size_t shdridx = 0; - - /* Create the full name of the file. */ - if (prefix != NULL) -@@ -543,6 +544,11 @@ handle_elf (int fd, Elf *elf, const char - goto fail_close; - } - -+ if (shstrndx >= shnum) -+ goto illformed; -+ -+#define elf_assert(test) do { if (!(test)) goto illformed; } while (0) -+ - /* Storage for section information. We leave room for two more - entries since we unconditionally create a section header string - table. Maybe some weird tool created an ELF file without one. -@@ -564,7 +570,7 @@ handle_elf (int fd, Elf *elf, const char - { - /* This should always be true (i.e., there should not be any - holes in the numbering). */ -- assert (elf_ndxscn (scn) == cnt); -+ elf_assert (elf_ndxscn (scn) == cnt); - - shdr_info[cnt].scn = scn; - -@@ -577,6 +583,7 @@ handle_elf (int fd, Elf *elf, const char - shdr_info[cnt].shdr.sh_name); - if (shdr_info[cnt].name == NULL) - { -+ illformed: - error (0, 0, gettext ("illformed file '%s'"), fname); - goto fail_close; - } -@@ -586,6 +593,8 @@ handle_elf (int fd, Elf *elf, const char - - /* Remember the shdr.sh_link value. */ - shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link; -+ if (shdr_info[cnt].old_sh_link >= shnum) -+ goto illformed; - - /* Sections in files other than relocatable object files which - are not loaded can be freely moved by us. In relocatable -@@ -598,7 +607,7 @@ handle_elf (int fd, Elf *elf, const char - appropriate reference. */ - if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX)) - { -- assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); -+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); - shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt; - } - else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP)) -@@ -615,7 +624,12 @@ handle_elf (int fd, Elf *elf, const char - for (inner = 1; - inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); - ++inner) -+ { -+ if (grpref[inner] < shnum) - shdr_info[grpref[inner]].group_idx = cnt; -+ else -+ goto illformed; -+ } - - if (inner == 1 || (inner == 2 && (grpref[0] & GRP_COMDAT) == 0)) - /* If the section group contains only one element and this -@@ -626,7 +640,7 @@ handle_elf (int fd, Elf *elf, const char - } - else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym)) - { -- assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); -+ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); - shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt; - } - -@@ -634,7 +648,7 @@ handle_elf (int fd, Elf *elf, const char - discarded right away. */ - if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0) - { -- assert (shdr_info[cnt].group_idx != 0); -+ elf_assert (shdr_info[cnt].group_idx != 0); - - if (shdr_info[shdr_info[cnt].group_idx].idx == 0) - { -@@ -709,11 +723,15 @@ handle_elf (int fd, Elf *elf, const char - { - /* If a relocation section is marked as being removed make - sure the section it is relocating is removed, too. */ -- if ((shdr_info[cnt].shdr.sh_type == SHT_REL -+ if (shdr_info[cnt].shdr.sh_type == SHT_REL - || shdr_info[cnt].shdr.sh_type == SHT_RELA) -- && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) -+ { -+ if (shdr_info[cnt].shdr.sh_info >= shnum) -+ goto illformed; -+ else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) - shdr_info[cnt].idx = 1; - } -+ } - - if (shdr_info[cnt].idx == 1) - { -@@ -738,7 +756,7 @@ handle_elf (int fd, Elf *elf, const char - if (shdr_info[cnt].symtab_idx != 0 - && shdr_info[shdr_info[cnt].symtab_idx].data == NULL) - { -- assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); -+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); - - shdr_info[shdr_info[cnt].symtab_idx].data - = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, -@@ -778,6 +796,9 @@ handle_elf (int fd, Elf *elf, const char - else if (scnidx == SHN_XINDEX) - scnidx = xndx; - -+ if (scnidx >= shnum) -+ goto illformed; -+ - if (shdr_info[scnidx].idx == 0) - { - /* Mark this section as used. */ -@@ -809,12 +830,16 @@ handle_elf (int fd, Elf *elf, const char - } - - /* Handle references through sh_info. */ -- if (SH_INFO_LINK_P (&shdr_info[cnt].shdr) -- && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) -+ if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) -+ { -+ if (shdr_info[cnt].shdr.sh_info >= shnum) -+ goto illformed; -+ else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) - { - shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1; - changes |= shdr_info[cnt].shdr.sh_info < cnt; - } -+ } - - /* Mark the section as investigated. */ - shdr_info[cnt].idx = 2; -@@ -953,7 +978,7 @@ handle_elf (int fd, Elf *elf, const char - error (EXIT_FAILURE, 0, gettext ("while generating output file: %s"), - elf_errmsg (-1)); - -- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); -+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); - - /* Add this name to the section header string table. */ - shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0); -@@ -990,7 +1015,7 @@ handle_elf (int fd, Elf *elf, const char - error (EXIT_FAILURE, 0, - gettext ("while create section header section: %s"), - elf_errmsg (-1)); -- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); -+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); - - shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn); - if (shdr_info[cnt].data == NULL) -@@ -1021,7 +1046,7 @@ handle_elf (int fd, Elf *elf, const char - } - - /* Index of the section header table in the shdr_info array. */ -- size_t shdridx = cnt; -+ shdridx = cnt; - - /* Add the section header string table section name. */ - shdr_info[cnt].se = ebl_strtabadd (shst, ".shstrtab", 10); -@@ -1046,7 +1071,7 @@ handle_elf (int fd, Elf *elf, const char - error (EXIT_FAILURE, 0, - gettext ("while create section header section: %s"), - elf_errmsg (-1)); -- assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); -+ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); - - /* Finalize the string table and fill in the correct indices in the - section headers. */ -@@ -1136,20 +1161,20 @@ handle_elf (int fd, Elf *elf, const char - shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, - NULL); - -- assert ((versiondata->d_size / sizeof (Elf32_Word)) -+ elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) - >= shdr_info[cnt].data->d_size / elsize); - } - - if (shdr_info[cnt].version_idx != 0) - { -- assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); -+ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); - /* This section has associated version - information. We have to modify that - information, too. */ - versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn, - NULL); - -- assert ((versiondata->d_size / sizeof (GElf_Versym)) -+ elf_assert ((versiondata->d_size / sizeof (GElf_Versym)) - >= shdr_info[cnt].data->d_size / elsize); - } - -@@ -1204,7 +1229,7 @@ handle_elf (int fd, Elf *elf, const char - sec = shdr_info[sym->st_shndx].idx; - else - { -- assert (shndxdata != NULL); -+ elf_assert (shndxdata != NULL); - - sec = shdr_info[xshndx].idx; - } -@@ -1225,7 +1250,7 @@ handle_elf (int fd, Elf *elf, const char - nxshndx = sec; - } - -- assert (sec < SHN_LORESERVE || shndxdata != NULL); -+ elf_assert (sec < SHN_LORESERVE || shndxdata != NULL); - - if ((inner != destidx || nshndx != sym->st_shndx - || (shndxdata != NULL && nxshndx != xshndx)) -@@ -1248,7 +1273,7 @@ handle_elf (int fd, Elf *elf, const char - else - /* This is a section symbol for a section which has - been removed. */ -- assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); -+ elf_assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); - } - - if (destidx != inner) -@@ -1441,11 +1466,11 @@ handle_elf (int fd, Elf *elf, const char - { - GElf_Sym sym_mem; - GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); -- assert (sym != NULL); -+ elf_assert (sym != NULL); - - const char *name = elf_strptr (elf, strshndx, - sym->st_name); -- assert (name != NULL); -+ elf_assert (name != NULL); - size_t hidx = elf_hash (name) % nbucket; - - if (bucket[hidx] == 0) -@@ -1464,7 +1489,7 @@ handle_elf (int fd, Elf *elf, const char - else - { - /* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */ -- assert (shdr_info[cnt].shdr.sh_entsize -+ elf_assert (shdr_info[cnt].shdr.sh_entsize - == sizeof (Elf64_Xword)); - - Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf; -@@ -1495,11 +1520,11 @@ handle_elf (int fd, Elf *elf, const char - { - GElf_Sym sym_mem; - GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); -- assert (sym != NULL); -+ elf_assert (sym != NULL); - - const char *name = elf_strptr (elf, strshndx, - sym->st_name); -- assert (name != NULL); -+ elf_assert (name != NULL); - size_t hidx = elf_hash (name) % nbucket; - - if (bucket[hidx] == 0) ---- elfutils-0.130/src/elflint.c.robustify -+++ elfutils-0.130/src/elflint.c +--- elfutils-0.132/src/elflint.c.robustify ++++ elfutils-0.132/src/elflint.c @@ -126,6 +126,9 @@ static uint32_t shstrndx; /* Array to count references in section groups. */ static int *scnref; @@ -590,7 +109,7 @@ src/ static void check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size) { -@@ -606,7 +614,8 @@ section [%2d] '%s': symbol table cannot +@@ -605,7 +613,8 @@ section [%2d] '%s': symbol table cannot } } @@ -598,18 +117,18 @@ src/ + size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT); + if (shdr->sh_entsize != sh_entsize) ERROR (gettext ("\ - section [%2zu] '%s': entry size is does not match ElfXX_Sym\n"), - cnt, section_name (ebl, cnt)); -@@ -644,7 +653,7 @@ section [%2d] '%s': XINDEX for zeroth en + section [%2u] '%s': entry size is does not match ElfXX_Sym\n"), + idx, section_name (ebl, idx)); +@@ -643,7 +652,7 @@ section [%2d] '%s': XINDEX for zeroth en xndxscnidx, section_name (ebl, xndxscnidx)); } -- for (cnt = 1; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) -+ for (cnt = 1; cnt < shdr->sh_size / sh_entsize; ++cnt) +- for (size_t cnt = 1; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) ++ for (size_t cnt = 1; cnt < shdr->sh_size / sh_entsize; ++cnt) { sym = gelf_getsymshndx (data, xndxdata, cnt, &sym_mem, &xndx); if (sym == NULL) -@@ -662,7 +671,8 @@ section [%2d] '%s': symbol %zu: invalid +@@ -661,7 +670,8 @@ section [%2d] '%s': symbol %zu: invalid else { name = elf_strptr (ebl->elf, shdr->sh_link, sym->st_name); @@ -619,7 +138,7 @@ src/ } if (sym->st_shndx == SHN_XINDEX) -@@ -992,9 +1002,11 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e +@@ -991,9 +1001,11 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e { GElf_Shdr rcshdr_mem; const GElf_Shdr *rcshdr = gelf_getshdr (scn, &rcshdr_mem); @@ -633,7 +152,7 @@ src/ { /* Found the dynamic section. Look through it. */ Elf_Data *d = elf_getdata (scn, NULL); -@@ -1004,7 +1016,9 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e +@@ -1003,7 +1015,9 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e { GElf_Dyn dyn_mem; GElf_Dyn *dyn = gelf_getdyn (d, cnt, &dyn_mem); @@ -644,7 +163,7 @@ src/ if (dyn->d_tag == DT_RELCOUNT) { -@@ -1018,7 +1032,9 @@ section [%2d] '%s': DT_RELCOUNT used for +@@ -1017,7 +1031,9 @@ section [%2d] '%s': DT_RELCOUNT used for /* Does the number specified number of relative relocations exceed the total number of relocations? */ @@ -655,7 +174,7 @@ src/ ERROR (gettext ("\ section [%2d] '%s': DT_RELCOUNT value %d too high for this section\n"), idx, section_name (ebl, idx), -@@ -1178,7 +1194,8 @@ section [%2d] '%s': no relocations for m +@@ -1177,7 +1193,8 @@ section [%2d] '%s': no relocations for m } } @@ -665,7 +184,7 @@ src/ ERROR (gettext (reltype == ELF_T_RELA ? "\ section [%2d] '%s': section entry size does not match ElfXX_Rela\n" : "\ section [%2d] '%s': section entry size does not match ElfXX_Rel\n"), -@@ -1401,7 +1418,8 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, G +@@ -1400,7 +1417,8 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, G Elf_Data *symdata = elf_getdata (symscn, NULL); enum load_state state = state_undecided; @@ -675,7 +194,7 @@ src/ { GElf_Rela rela_mem; GElf_Rela *rela = gelf_getrela (data, cnt, &rela_mem); -@@ -1451,7 +1469,8 @@ check_rel (Ebl *ebl, GElf_Ehdr *ehdr, GE +@@ -1450,7 +1468,8 @@ check_rel (Ebl *ebl, GElf_Ehdr *ehdr, GE Elf_Data *symdata = elf_getdata (symscn, NULL); enum load_state state = state_undecided; @@ -685,7 +204,7 @@ src/ { GElf_Rel rel_mem; GElf_Rel *rel = gelf_getrel (data, cnt, &rel_mem); -@@ -1555,7 +1574,8 @@ section [%2d] '%s': referenced as string +@@ -1553,7 +1572,8 @@ section [%2d] '%s': referenced as string shdr->sh_link, section_name (ebl, shdr->sh_link), idx, section_name (ebl, idx)); @@ -695,7 +214,7 @@ src/ ERROR (gettext ("\ section [%2d] '%s': section entry size does not match ElfXX_Dyn\n"), idx, section_name (ebl, idx)); -@@ -1565,7 +1585,7 @@ section [%2d] '%s': section entry size d +@@ -1563,7 +1583,7 @@ section [%2d] '%s': section entry size d idx, section_name (ebl, idx)); bool non_null_warned = false; @@ -704,7 +223,7 @@ src/ { GElf_Dyn dyn_mem; GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dyn_mem); -@@ -1846,6 +1866,8 @@ section [%2d] '%s': entry size does not +@@ -1844,6 +1864,8 @@ section [%2d] '%s': entry size does not idx, section_name (ebl, idx)); if (symshdr != NULL @@ -713,7 +232,7 @@ src/ && (shdr->sh_size / shdr->sh_entsize < symshdr->sh_size / symshdr->sh_entsize)) ERROR (gettext ("\ -@@ -1872,6 +1894,12 @@ section [%2d] '%s': extended section ind +@@ -1870,6 +1892,12 @@ section [%2d] '%s': extended section ind } Elf_Data *data = elf_getdata (elf_getscn (ebl->elf, idx), NULL); @@ -726,7 +245,7 @@ src/ if (*((Elf32_Word *) data->d_buf) != 0) ERROR (gettext ("symbol 0 should have zero extended section index\n")); -@@ -1914,7 +1942,7 @@ section [%2d] '%s': hash table section i +@@ -1912,7 +1940,7 @@ section [%2d] '%s': hash table section i size_t maxidx = nchain; @@ -735,7 +254,7 @@ src/ { size_t symsize = symshdr->sh_size / symshdr->sh_entsize; -@@ -1925,18 +1953,28 @@ section [%2d] '%s': hash table section i +@@ -1923,18 +1951,28 @@ section [%2d] '%s': hash table section i maxidx = symsize; } @@ -766,7 +285,7 @@ src/ } -@@ -1966,18 +2004,28 @@ section [%2d] '%s': hash table section i +@@ -1964,18 +2002,28 @@ section [%2d] '%s': hash table section i maxidx = symsize; } @@ -798,7 +317,7 @@ src/ } -@@ -2002,7 +2050,7 @@ section [%2d] '%s': bitmask size not pow +@@ -2000,7 +2048,7 @@ section [%2d] '%s': bitmask size not pow if (shdr->sh_size < (4 + bitmask_words + nbuckets) * sizeof (Elf32_Word)) { ERROR (gettext ("\ @@ -807,7 +326,7 @@ src/ idx, section_name (ebl, idx), (long int) shdr->sh_size, (long int) ((4 + bitmask_words + nbuckets) * sizeof (Elf32_Word))); return; -@@ -2659,8 +2707,9 @@ section [%2d] '%s' refers in sh_link to +@@ -2657,8 +2705,9 @@ section [%2d] '%s' refers in sh_link to /* The number of elements in the version symbol table must be the same as the number of symbols. */ @@ -819,8 +338,992 @@ src/ ERROR (gettext ("\ section [%2d] '%s' has different number of entries than symbol table [%2d] '%s'\n"), idx, section_name (ebl, idx), ---- elfutils-0.127/libelf/elf_begin.c.robustify -+++ elfutils-0.127/libelf/elf_begin.c +--- elfutils-0.132/src/readelf.c.robustify ++++ elfutils-0.132/src/readelf.c +@@ -1107,6 +1107,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G + Elf32_Word *grpref = (Elf32_Word *) data->d_buf; + + GElf_Sym sym_mem; ++ GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem); ++ + printf ((grpref[0] & GRP_COMDAT) + ? ngettext ("\ + \nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n", +@@ -1119,8 +1121,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G + data->d_size / sizeof (Elf32_Word) - 1), + elf_ndxscn (scn), + elf_strptr (ebl->elf, shstrndx, shdr->sh_name), +- elf_strptr (ebl->elf, symshdr->sh_link, +- gelf_getsym (symdata, shdr->sh_info, &sym_mem)->st_name) ++ (sym == NULL ? NULL ++ : elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name)) + ?: gettext (""), + data->d_size / sizeof (Elf32_Word) - 1); + +@@ -1271,7 +1273,8 @@ static void + handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr) + { + int class = gelf_getclass (ebl->elf); +- GElf_Shdr glink; ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink; + Elf_Data *data; + size_t cnt; + size_t shstrndx; +@@ -1286,6 +1289,11 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, + error (EXIT_FAILURE, 0, + gettext ("cannot get section header string table index")); + ++ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); ++ if (glink == NULL) ++ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ + printf (ngettext ("\ + \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", + "\ +@@ -1295,9 +1303,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, + class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, + shdr->sh_offset, + (int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + fputs_unlocked (gettext (" Type Value\n"), stdout); + + for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) +@@ -1797,6 +1803,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G + error (EXIT_FAILURE, 0, + gettext ("cannot get section header string table index")); + ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), ++ &glink_mem); ++ if (glink == NULL) ++ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ + /* Now we can compute the number of entries in the section. */ + unsigned int nsyms = data->d_size / (class == ELFCLASS32 + ? sizeof (Elf32_Sym) +@@ -1807,15 +1820,12 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G + nsyms), + (unsigned int) elf_ndxscn (scn), + elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms); +- GElf_Shdr glink; + printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n", + " %lu local symbols String table: [%2u] '%s'\n", + shdr->sh_info), + (unsigned long int) shdr->sh_info, + (unsigned int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + + fputs_unlocked (class == ELFCLASS32 + ? gettext ("\ +@@ -2051,7 +2061,13 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, + error (EXIT_FAILURE, 0, + gettext ("cannot get section header string table index")); + +- GElf_Shdr glink; ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), ++ &glink_mem); ++ if (glink == NULL) ++ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ + printf (ngettext ("\ + \nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", + "\ +@@ -2062,9 +2078,7 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn, + class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, + shdr->sh_offset, + (unsigned int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + + unsigned int offset = 0; + for (int cnt = shdr->sh_info; --cnt >= 0; ) +@@ -2117,8 +2131,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G + error (EXIT_FAILURE, 0, + gettext ("cannot get section header string table index")); + ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), ++ &glink_mem); ++ if (glink == NULL) ++ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ + int class = gelf_getclass (ebl->elf); +- GElf_Shdr glink; + printf (ngettext ("\ + \nVersion definition section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n", + "\ +@@ -2130,9 +2150,7 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G + class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, + shdr->sh_offset, + (unsigned int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + + unsigned int offset = 0; + for (int cnt = shdr->sh_info; --cnt >= 0; ) +@@ -2394,8 +2412,14 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G + filename = NULL; + } + ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), ++ &glink_mem); ++ if (glink == NULL) ++ error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ + /* Print the header. */ +- GElf_Shdr glink; + printf (ngettext ("\ + \nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'", + "\ +@@ -2407,9 +2431,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G + class == ELFCLASS32 ? 10 : 18, shdr->sh_addr, + shdr->sh_offset, + (unsigned int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + + /* Now we can finally look at the actual contents of this section. */ + for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt) +@@ -2461,7 +2483,17 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, + for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt) + ++counts[lengths[cnt]]; + +- GElf_Shdr glink; ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, ++ shdr->sh_link), ++ &glink_mem); ++ if (glink == NULL) ++ { ++ error (0, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ return; ++ } ++ + printf (ngettext ("\ + \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", + "\ +@@ -2474,9 +2506,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn, + shdr->sh_addr, + shdr->sh_offset, + (unsigned int) shdr->sh_link, +- elf_strptr (ebl->elf, shstrndx, +- gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), +- &glink)->sh_name)); ++ elf_strptr (ebl->elf, shstrndx, glink->sh_name)); + + if (extrastr != NULL) + fputs (extrastr, stdout); +@@ -3875,6 +3905,16 @@ print_debug_aranges_section (Dwfl_Module + return; + } + ++ GElf_Shdr glink_mem; ++ GElf_Shdr *glink; ++ glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem); ++ if (glink == NULL) ++ { ++ error (0, 0, gettext ("invalid sh_link value in section %Zu"), ++ elf_ndxscn (scn)); ++ return; ++ } ++ + printf (ngettext ("\ + \nDWARF section '%s' at offset %#" PRIx64 " contains %zu entry:\n", + "\ +--- elfutils-0.132/src/strip.c.robustify ++++ elfutils-0.132/src/strip.c +@@ -543,6 +543,11 @@ handle_elf (int fd, Elf *elf, const char + goto fail_close; + } + ++ if (shstrndx >= shnum) ++ goto illformed; ++ ++#define elf_assert(test) do { if (!(test)) goto illformed; } while (0) ++ + /* Storage for section information. We leave room for two more + entries since we unconditionally create a section header string + table. Maybe some weird tool created an ELF file without one. +@@ -564,7 +569,7 @@ handle_elf (int fd, Elf *elf, const char + { + /* This should always be true (i.e., there should not be any + holes in the numbering). */ +- assert (elf_ndxscn (scn) == cnt); ++ elf_assert (elf_ndxscn (scn) == cnt); + + shdr_info[cnt].scn = scn; + +@@ -577,6 +582,7 @@ handle_elf (int fd, Elf *elf, const char + shdr_info[cnt].shdr.sh_name); + if (shdr_info[cnt].name == NULL) + { ++ illformed: + error (0, 0, gettext ("illformed file '%s'"), fname); + goto fail_close; + } +@@ -586,6 +592,8 @@ handle_elf (int fd, Elf *elf, const char + + /* Remember the shdr.sh_link value. */ + shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link; ++ if (shdr_info[cnt].old_sh_link >= shnum) ++ goto illformed; + + /* Sections in files other than relocatable object files which + are not loaded can be freely moved by us. In relocatable +@@ -598,7 +606,7 @@ handle_elf (int fd, Elf *elf, const char + appropriate reference. */ + if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX)) + { +- assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); ++ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0); + shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt; + } + else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP)) +@@ -615,7 +623,12 @@ handle_elf (int fd, Elf *elf, const char + for (inner = 1; + inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word); + ++inner) ++ { ++ if (grpref[inner] < shnum) + shdr_info[grpref[inner]].group_idx = cnt; ++ else ++ goto illformed; ++ } + + if (inner == 1 || (inner == 2 && (grpref[0] & GRP_COMDAT) == 0)) + /* If the section group contains only one element and this +@@ -626,7 +639,7 @@ handle_elf (int fd, Elf *elf, const char + } + else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym)) + { +- assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); ++ elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0); + shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt; + } + +@@ -634,7 +647,7 @@ handle_elf (int fd, Elf *elf, const char + discarded right away. */ + if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0) + { +- assert (shdr_info[cnt].group_idx != 0); ++ elf_assert (shdr_info[cnt].group_idx != 0); + + if (shdr_info[shdr_info[cnt].group_idx].idx == 0) + { +@@ -709,11 +722,15 @@ handle_elf (int fd, Elf *elf, const char + { + /* If a relocation section is marked as being removed make + sure the section it is relocating is removed, too. */ +- if ((shdr_info[cnt].shdr.sh_type == SHT_REL ++ if (shdr_info[cnt].shdr.sh_type == SHT_REL + || shdr_info[cnt].shdr.sh_type == SHT_RELA) +- && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) ++ { ++ if (shdr_info[cnt].shdr.sh_info >= shnum) ++ goto illformed; ++ else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0) + shdr_info[cnt].idx = 1; + } ++ } + + if (shdr_info[cnt].idx == 1) + { +@@ -738,7 +755,7 @@ handle_elf (int fd, Elf *elf, const char + if (shdr_info[cnt].symtab_idx != 0 + && shdr_info[shdr_info[cnt].symtab_idx].data == NULL) + { +- assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); ++ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB); + + shdr_info[shdr_info[cnt].symtab_idx].data + = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, +@@ -778,6 +795,9 @@ handle_elf (int fd, Elf *elf, const char + else if (scnidx == SHN_XINDEX) + scnidx = xndx; + ++ if (scnidx >= shnum) ++ goto illformed; ++ + if (shdr_info[scnidx].idx == 0) + { + /* Mark this section as used. */ +@@ -809,12 +829,16 @@ handle_elf (int fd, Elf *elf, const char + } + + /* Handle references through sh_info. */ +- if (SH_INFO_LINK_P (&shdr_info[cnt].shdr) +- && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) ++ if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) ++ { ++ if (shdr_info[cnt].shdr.sh_info >= shnum) ++ goto illformed; ++ else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0) + { + shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1; + changes |= shdr_info[cnt].shdr.sh_info < cnt; + } ++ } + + /* Mark the section as investigated. */ + shdr_info[cnt].idx = 2; +@@ -914,7 +938,7 @@ handle_elf (int fd, Elf *elf, const char + error (EXIT_FAILURE, 0, gettext ("while generating output file: %s"), + elf_errmsg (-1)); + +- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); ++ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); + + /* Add this name to the section header string table. */ + shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0); +@@ -951,7 +975,7 @@ handle_elf (int fd, Elf *elf, const char + error (EXIT_FAILURE, 0, + gettext ("while create section header section: %s"), + elf_errmsg (-1)); +- assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); ++ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx); + + shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn); + if (shdr_info[cnt].data == NULL) +@@ -1007,7 +1031,7 @@ handle_elf (int fd, Elf *elf, const char + error (EXIT_FAILURE, 0, + gettext ("while create section header section: %s"), + elf_errmsg (-1)); +- assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); ++ elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx); + + /* Finalize the string table and fill in the correct indices in the + section headers. */ +@@ -1097,20 +1121,20 @@ handle_elf (int fd, Elf *elf, const char + shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn, + NULL); + +- assert ((versiondata->d_size / sizeof (Elf32_Word)) ++ elf_assert ((versiondata->d_size / sizeof (Elf32_Word)) + >= shdr_info[cnt].data->d_size / elsize); + } + + if (shdr_info[cnt].version_idx != 0) + { +- assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); ++ elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM); + /* This section has associated version + information. We have to modify that + information, too. */ + versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn, + NULL); + +- assert ((versiondata->d_size / sizeof (GElf_Versym)) ++ elf_assert ((versiondata->d_size / sizeof (GElf_Versym)) + >= shdr_info[cnt].data->d_size / elsize); + } + +@@ -1165,7 +1189,7 @@ handle_elf (int fd, Elf *elf, const char + sec = shdr_info[sym->st_shndx].idx; + else + { +- assert (shndxdata != NULL); ++ elf_assert (shndxdata != NULL); + + sec = shdr_info[xshndx].idx; + } +@@ -1186,7 +1210,7 @@ handle_elf (int fd, Elf *elf, const char + nxshndx = sec; + } + +- assert (sec < SHN_LORESERVE || shndxdata != NULL); ++ elf_assert (sec < SHN_LORESERVE || shndxdata != NULL); + + if ((inner != destidx || nshndx != sym->st_shndx + || (shndxdata != NULL && nxshndx != xshndx)) +@@ -1209,7 +1233,7 @@ handle_elf (int fd, Elf *elf, const char + else + /* This is a section symbol for a section which has + been removed. */ +- assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); ++ elf_assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION); + } + + if (destidx != inner) +@@ -1388,11 +1412,11 @@ handle_elf (int fd, Elf *elf, const char + { + GElf_Sym sym_mem; + GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); +- assert (sym != NULL); ++ elf_assert (sym != NULL); + + const char *name = elf_strptr (elf, strshndx, + sym->st_name); +- assert (name != NULL); ++ elf_assert (name != NULL); + size_t hidx = elf_hash (name) % nbucket; + + if (bucket[hidx] == 0) +@@ -1411,7 +1435,7 @@ handle_elf (int fd, Elf *elf, const char + else + { + /* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */ +- assert (shdr_info[cnt].shdr.sh_entsize ++ elf_assert (shdr_info[cnt].shdr.sh_entsize + == sizeof (Elf64_Xword)); + + Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf; +@@ -1442,11 +1466,11 @@ handle_elf (int fd, Elf *elf, const char + { + GElf_Sym sym_mem; + GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem); +- assert (sym != NULL); ++ elf_assert (sym != NULL); + + const char *name = elf_strptr (elf, strshndx, + sym->st_name); +- assert (name != NULL); ++ elf_assert (name != NULL); + size_t hidx = elf_hash (name) % nbucket; + + if (bucket[hidx] == 0) +--- elfutils-0.132/libelf/gelf_getdyn.c.robustify ++++ elfutils-0.132/libelf/gelf_getdyn.c +@@ -93,7 +93,8 @@ gelf_getdyn (data, ndx, dst) + table entries has to be adopted. The user better has provided + a buffer where we can store the information. While copying the + data we are converting the format. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Dyn) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -114,7 +115,8 @@ gelf_getdyn (data, ndx, dst) + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, GElf_Dyn) ++ || unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_getrel.c.robustify ++++ elfutils-0.132/libelf/gelf_getrel.c +@@ -71,12 +71,6 @@ gelf_getrel (data, ndx, dst) + if (data_scn == NULL) + return NULL; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return NULL; +- } +- + if (unlikely (data_scn->d.d_type != ELF_T_REL)) + { + __libelf_seterrno (ELF_E_INVALID_HANDLE); +@@ -93,7 +87,8 @@ gelf_getrel (data, ndx, dst) + if (scn->elf->class == ELFCLASS32) + { + /* We have to convert the data. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Rel) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + result = NULL; +@@ -113,7 +108,8 @@ gelf_getrel (data, ndx, dst) + { + /* Simply copy the data after we made sure we are actually getting + correct data. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Rel) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + result = NULL; +--- elfutils-0.132/libelf/gelf_getversym.c.robustify ++++ elfutils-0.132/libelf/gelf_getversym.c +@@ -92,7 +92,8 @@ gelf_getversym (data, ndx, dst) + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) ++ if (INVALID_NDX (ndx, GElf_Versym) ++ || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + result = NULL; +--- elfutils-0.132/libelf/elf_newscn.c.robustify ++++ elfutils-0.132/libelf/elf_newscn.c +@@ -104,10 +104,18 @@ elf_newscn (elf) + else + { + /* We must allocate a new element. */ +- Elf_ScnList *newp; ++ Elf_ScnList *newp = NULL; + + assert (elf->state.elf.scnincr > 0); + ++ if ( ++#if SIZE_MAX <= 4294967295U ++ likely (elf->state.elf.scnincr ++ < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList)) ++#else ++ 1 ++#endif ++ ) + newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList) + + ((elf->state.elf.scnincr *= 2) + * sizeof (Elf_Scn)), 1); +--- elfutils-0.132/libelf/elf32_getshdr.c.robustify ++++ elfutils-0.132/libelf/elf32_getshdr.c +@@ -101,7 +101,8 @@ elfw2(LIBELFBITS,getshdr) (scn) + goto out; + + size_t shnum; +- if (INTUSE (elf_getshnum) (elf, &shnum) != 0) ++ if (INTUSE (elf_getshnum) (elf, &shnum) != 0 ++ || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr))) + goto out; + size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr)); + +@@ -118,6 +119,16 @@ elfw2(LIBELFBITS,getshdr) (scn) + + if (elf->map_address != NULL) + { ++ /* First see whether the information in the ELF header is ++ valid and it does not ask for too much. */ ++ if (unlikely (ehdr->e_shoff >= elf->maximum_size) ++ || unlikely (ehdr->e_shoff + size > elf->maximum_size)) ++ { ++ /* Something is wrong. */ ++ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); ++ goto free_and_out; ++ } ++ + ElfW2(LIBELFBITS,Shdr) *notcvt; + + /* All the data is already mapped. If we could use it +--- elfutils-0.132/libelf/gelf_getsymshndx.c.robustify ++++ elfutils-0.132/libelf/gelf_getsymshndx.c +@@ -90,7 +90,9 @@ gelf_getsymshndx (symdata, shndxdata, nd + section index table. */ + if (likely (shndxdata_scn != NULL)) + { +- if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Word) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Word) ++ > shndxdata_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -110,7 +112,8 @@ gelf_getsymshndx (symdata, shndxdata, nd + table entries has to be adopted. The user better has provided + a buffer where we can store the information. While copying the + data we are converting the format. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) ++ if (INVALID_NDX (ndx, Elf32_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -139,7 +142,8 @@ gelf_getsymshndx (symdata, shndxdata, nd + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) ++ if (INVALID_NDX (ndx, GElf_Sym) ++ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_update_versym.c.robustify ++++ elfutils-0.132/libelf/gelf_update_versym.c +@@ -75,7 +75,7 @@ gelf_update_versym (data, ndx, src) + assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym)); + + /* Check whether we have to resize the data buffer. */ +- if (unlikely (ndx < 0) ++ if (INVALID_NDX (ndx, GElf_Versym) + || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); +--- elfutils-0.132/libelf/elf_getshstrndx.c.robustify ++++ elfutils-0.132/libelf/elf_getshstrndx.c +@@ -125,10 +125,25 @@ elf_getshstrndx (elf, dst) + if (elf->map_address != NULL + && elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA + && (ALLOW_UNALIGNED +- || (((size_t) ((char *) elf->map_address + offset)) ++ || (((size_t) ((char *) elf->map_address ++ + elf->start_offset + offset)) + & (__alignof__ (Elf32_Shdr) - 1)) == 0)) ++ { ++ /* First see whether the information in the ELF header is ++ valid and it does not ask for too much. */ ++ if (unlikely (offset + sizeof (Elf32_Shdr) ++ > elf->maximum_size)) ++ { ++ /* Something is wrong. */ ++ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); ++ result = -1; ++ goto out; ++ } ++ + /* We can directly access the memory. */ +- num = ((Elf32_Shdr *) (elf->map_address + offset))->sh_link; ++ num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset ++ + offset))->sh_link; ++ } + else + { + /* We avoid reading in all the section headers. Just read +@@ -163,10 +178,25 @@ elf_getshstrndx (elf, dst) + if (elf->map_address != NULL + && elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA + && (ALLOW_UNALIGNED +- || (((size_t) ((char *) elf->map_address + offset)) ++ || (((size_t) ((char *) elf->map_address ++ + elf->start_offset + offset)) + & (__alignof__ (Elf64_Shdr) - 1)) == 0)) ++ { ++ /* First see whether the information in the ELF header is ++ valid and it does not ask for too much. */ ++ if (unlikely (offset + sizeof (Elf64_Shdr) ++ > elf->maximum_size)) ++ { ++ /* Something is wrong. */ ++ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); ++ result = -1; ++ goto out; ++ } ++ + /* We can directly access the memory. */ +- num = ((Elf64_Shdr *) (elf->map_address + offset))->sh_link; ++ num = ((Elf64_Shdr *) (elf->map_address ++ + elf->start_offset + offset))->sh_link; ++ } + else + { + /* We avoid reading in all the section headers. Just read +--- elfutils-0.132/libelf/libelfP.h.robustify ++++ elfutils-0.132/libelf/libelfP.h +@@ -596,4 +596,13 @@ extern uint32_t __libelf_crc32 (uint32_t + /* Align offset to 4 bytes as needed for note name and descriptor data. */ + #define NOTE_ALIGN(n) (((n) + 3) & -4U) + ++/* Convenience macro. Assumes int NDX and TYPE with size at least ++ 2 bytes. */ ++#if SIZE_MAX > 4294967295U ++# define INVALID_NDX(ndx, type) unlikely (ndx < 0) ++#else ++# define INVALID_NDX(ndx, type) \ ++ unlikely ((unsigned int) (ndx) >= SIZE_MAX / sizeof (type)) ++#endif ++ + #endif /* libelfP.h */ +--- elfutils-0.132/libelf/gelf_getmove.c.robustify ++++ elfutils-0.132/libelf/gelf_getmove.c +@@ -83,7 +83,8 @@ gelf_getmove (data, ndx, dst) + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) ++ if (INVALID_NDX (ndx, GElf_Move) ++ || unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/elf32_updatefile.c.robustify ++++ elfutils-0.132/libelf/elf32_updatefile.c +@@ -212,6 +212,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf + /* Write all the sections. Well, only those which are modified. */ + if (shnum > 0) + { ++ if (unlikely (shnum > SIZE_MAX / sizeof (Elf_Scn *))) ++ return 1; ++ + Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns; + Elf_Scn **scns = (Elf_Scn **) alloca (shnum * sizeof (Elf_Scn *)); + char *const shdr_start = ((char *) elf->map_address + elf->start_offset +@@ -582,6 +585,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf + /* Write all the sections. Well, only those which are modified. */ + if (shnum > 0) + { ++ if (unlikely (shnum > SIZE_MAX / (sizeof (Elf_Scn *) ++ + sizeof (ElfW2(LIBELFBITS,Shdr))))) ++ return 1; ++ + off_t shdr_offset = elf->start_offset + ehdr->e_shoff; + #if EV_NUM != 2 + xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR]; +--- elfutils-0.132/libelf/gelf_update_lib.c.robustify ++++ elfutils-0.132/libelf/gelf_update_lib.c +@@ -68,12 +68,6 @@ gelf_update_lib (data, ndx, src) + if (data == NULL) + return 0; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return 0; +- } +- + Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data; + if (unlikely (data_scn->d.d_type != ELF_T_LIB)) + { +@@ -87,7 +81,8 @@ gelf_update_lib (data, ndx, src) + + /* Check whether we have to resize the data buffer. */ + int result = 0; +- if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Lib) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) + __libelf_seterrno (ELF_E_INVALID_INDEX); + else + { +--- elfutils-0.132/libelf/elf32_getphdr.c.robustify ++++ elfutils-0.132/libelf/elf32_getphdr.c +@@ -116,6 +116,16 @@ elfw2(LIBELFBITS,getphdr) (elf) + + if (elf->map_address != NULL) + { ++ /* First see whether the information in the ELF header is ++ valid and it does not ask for too much. */ ++ if (unlikely (ehdr->e_phoff >= elf->maximum_size) ++ || unlikely (ehdr->e_phoff + size > elf->maximum_size)) ++ { ++ /* Something is wrong. */ ++ __libelf_seterrno (ELF_E_INVALID_PHDR); ++ goto out; ++ } ++ + /* All the data is already mapped. Use it. */ + void *file_phdr = ((char *) elf->map_address + + elf->start_offset + ehdr->e_phoff); +--- elfutils-0.132/libelf/gelf_getlib.c.robustify ++++ elfutils-0.132/libelf/gelf_getlib.c +@@ -86,7 +86,8 @@ gelf_getlib (data, ndx, dst) + /* The data is already in the correct form. Just make sure the + index is OK. */ + GElf_Lib *result = NULL; +- if (unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) ++ if (INVALID_NDX (ndx, GElf_Lib) ++ || unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) + __libelf_seterrno (ELF_E_INVALID_INDEX); + else + { +--- elfutils-0.132/libelf/elf32_newphdr.c.robustify ++++ elfutils-0.132/libelf/elf32_newphdr.c +@@ -124,6 +124,12 @@ elfw2(LIBELFBITS,newphdr) (elf, count) + else if (elf->state.ELFW(elf,LIBELFBITS).ehdr->e_phnum != count + || elf->state.ELFW(elf,LIBELFBITS).phdr == NULL) + { ++ if (unlikely (count > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Phdr)))) ++ { ++ result = NULL; ++ goto out; ++ } ++ + /* Allocate a new program header with the appropriate number of + elements. */ + result = (ElfW2(LIBELFBITS,Phdr) *) +--- elfutils-0.132/libelf/gelf_update_rela.c.robustify ++++ elfutils-0.132/libelf/gelf_update_rela.c +@@ -68,12 +68,6 @@ gelf_update_rela (Elf_Data *dst, int ndx + if (dst == NULL) + return 0; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return 0; +- } +- + if (unlikely (data_scn->d.d_type != ELF_T_RELA)) + { + /* The type of the data better should match. */ +@@ -101,7 +95,8 @@ gelf_update_rela (Elf_Data *dst, int ndx + } + + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Rela) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -117,7 +112,8 @@ gelf_update_rela (Elf_Data *dst, int ndx + else + { + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Rela) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_update_syminfo.c.robustify ++++ elfutils-0.132/libelf/gelf_update_syminfo.c +@@ -72,12 +72,6 @@ gelf_update_syminfo (data, ndx, src) + if (data == NULL) + return 0; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return 0; +- } +- + if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO)) + { + /* The type of the data better should match. */ +@@ -93,7 +87,8 @@ gelf_update_syminfo (data, ndx, src) + rwlock_wrlock (scn->elf->lock); + + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, GElf_Syminfo) ++ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_update_sym.c.robustify ++++ elfutils-0.132/libelf/gelf_update_sym.c +@@ -72,12 +72,6 @@ gelf_update_sym (data, ndx, src) + if (data == NULL) + return 0; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return 0; +- } +- + if (unlikely (data_scn->d.d_type != ELF_T_SYM)) + { + /* The type of the data better should match. */ +@@ -102,7 +96,8 @@ gelf_update_sym (data, ndx, src) + } + + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -125,7 +120,8 @@ gelf_update_sym (data, ndx, src) + else + { + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_getsyminfo.c.robustify ++++ elfutils-0.132/libelf/gelf_getsyminfo.c +@@ -84,7 +84,8 @@ gelf_getsyminfo (data, ndx, dst) + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) ++ if (INVALID_NDX (ndx, GElf_Syminfo) ++ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_update_symshndx.c.robustify ++++ elfutils-0.132/libelf/gelf_update_symshndx.c +@@ -77,12 +77,6 @@ gelf_update_symshndx (symdata, shndxdata + if (symdata == NULL) + return 0; + +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return 0; +- } +- + if (unlikely (symdata_scn->d.d_type != ELF_T_SYM)) + { + /* The type of the data better should match. */ +@@ -128,7 +122,8 @@ gelf_update_symshndx (symdata, shndxdata + } + + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -151,7 +146,8 @@ gelf_update_symshndx (symdata, shndxdata + else + { + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/elf_getarsym.c.robustify ++++ elfutils-0.132/libelf/elf_getarsym.c +@@ -179,6 +179,9 @@ elf_getarsym (elf, ptr) + size_t index_size = atol (tmpbuf); + + if (SARMAG + sizeof (struct ar_hdr) + index_size > elf->maximum_size ++#if SIZE_MAX <= 4294967295U ++ || n >= SIZE_MAX / sizeof (Elf_Arsym) ++#endif + || n * sizeof (uint32_t) > index_size) + { + /* This index table cannot be right since it does not fit into +--- elfutils-0.132/libelf/gelf_getsym.c.robustify ++++ elfutils-0.132/libelf/gelf_getsym.c +@@ -90,7 +90,8 @@ gelf_getsym (data, ndx, dst) + table entries has to be adopted. The user better has provided + a buffer where we can store the information. While copying the + data we are converting the format. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) ++ if (INVALID_NDX (ndx, Elf32_Sym) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -119,7 +120,8 @@ gelf_getsym (data, ndx, dst) + + /* The data is already in the correct form. Just make sure the + index is OK. */ +- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) ++ if (INVALID_NDX (ndx, GElf_Sym) ++ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/elf_begin.c.robustify ++++ elfutils-0.132/libelf/elf_begin.c @@ -155,7 +155,8 @@ get_shnum (void *map_address, unsigned c if (unlikely (result == 0) && ehdr.e32->e_shoff != 0) @@ -889,7 +1392,7 @@ src/ for (size_t cnt = 0; cnt < scncnt; ++cnt) { -@@ -383,13 +412,26 @@ file_read_elf (int fildes, void *map_add +@@ -396,13 +425,26 @@ file_read_elf (int fildes, void *map_add { /* We can use the mmapped memory. */ elf->state.elf64.ehdr = ehdr; @@ -916,456 +1419,8 @@ src/ for (size_t cnt = 0; cnt < scncnt; ++cnt) { ---- elfutils-0.127/libelf/libelfP.h.robustify -+++ elfutils-0.127/libelf/libelfP.h -@@ -574,4 +574,13 @@ extern uint32_t __libelf_crc32 (uint32_t - } \ - } while (0) - -+/* Convenience macro. Assumes int NDX and TYPE with size at least -+ 2 bytes. */ -+#if SIZE_MAX > 4294967295U -+# define INVALID_NDX(ndx, type) unlikely (ndx < 0) -+#else -+# define INVALID_NDX(ndx, type) \ -+ unlikely ((unsigned int) (ndx) >= SIZE_MAX / sizeof (type)) -+#endif -+ - #endif /* libelfP.h */ ---- elfutils-0.127/libelf/gelf_update_move.c.robustify -+++ elfutils-0.127/libelf/gelf_update_move.c -@@ -75,7 +75,7 @@ gelf_update_move (data, ndx, src) - assert (sizeof (GElf_Move) == sizeof (Elf64_Move)); - - /* Check whether we have to resize the data buffer. */ -- if (unlikely (ndx < 0) -+ if (INVALID_NDX (ndx, GElf_Move) - || unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); ---- elfutils-0.127/libelf/gelf_getsym.c.robustify -+++ elfutils-0.127/libelf/gelf_getsym.c -@@ -90,7 +90,8 @@ gelf_getsym (data, ndx, dst) - table entries has to be adopted. The user better has provided - a buffer where we can store the information. While copying the - data we are converting the format. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) -+ if (INVALID_NDX (ndx, Elf32_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -119,7 +120,8 @@ gelf_getsym (data, ndx, dst) - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) -+ if (INVALID_NDX (ndx, GElf_Sym) -+ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_getrela.c.robustify -+++ elfutils-0.127/libelf/gelf_getrela.c -@@ -71,12 +71,6 @@ gelf_getrela (data, ndx, dst) - if (data_scn == NULL) - return NULL; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return NULL; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_RELA)) - { - __libelf_seterrno (ELF_E_INVALID_HANDLE); -@@ -93,7 +87,8 @@ gelf_getrela (data, ndx, dst) - if (scn->elf->class == ELFCLASS32) - { - /* We have to convert the data. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Rela) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - result = NULL; -@@ -114,7 +109,8 @@ gelf_getrela (data, ndx, dst) - { - /* Simply copy the data after we made sure we are actually getting - correct data. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Rela) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - result = NULL; ---- elfutils-0.127/libelf/gelf_getmove.c.robustify -+++ elfutils-0.127/libelf/gelf_getmove.c -@@ -83,7 +83,8 @@ gelf_getmove (data, ndx, dst) - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) -+ if (INVALID_NDX (ndx, GElf_Move) -+ || unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_update_symshndx.c.robustify -+++ elfutils-0.127/libelf/gelf_update_symshndx.c -@@ -77,12 +77,6 @@ gelf_update_symshndx (symdata, shndxdata - if (symdata == NULL) - return 0; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return 0; -- } -- - if (unlikely (symdata_scn->d.d_type != ELF_T_SYM)) - { - /* The type of the data better should match. */ -@@ -128,7 +122,8 @@ gelf_update_symshndx (symdata, shndxdata - } - - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -151,7 +146,8 @@ gelf_update_symshndx (symdata, shndxdata - else - { - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_update_dyn.c.robustify -+++ elfutils-0.127/libelf/gelf_update_dyn.c -@@ -71,12 +71,6 @@ gelf_update_dyn (data, ndx, src) - if (data == NULL) - return 0; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return 0; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_DYN)) - { - /* The type of the data better should match. */ -@@ -102,7 +96,8 @@ gelf_update_dyn (data, ndx, src) - } - - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Dyn) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -116,7 +111,8 @@ gelf_update_dyn (data, ndx, src) - else - { - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Dyn) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_update_rela.c.robustify -+++ elfutils-0.127/libelf/gelf_update_rela.c -@@ -68,12 +68,6 @@ gelf_update_rela (Elf_Data *dst, int ndx - if (dst == NULL) - return 0; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return 0; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_RELA)) - { - /* The type of the data better should match. */ -@@ -101,7 +95,8 @@ gelf_update_rela (Elf_Data *dst, int ndx - } - - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Rela) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -117,7 +112,8 @@ gelf_update_rela (Elf_Data *dst, int ndx - else - { - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Rela) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_getsymshndx.c.robustify -+++ elfutils-0.127/libelf/gelf_getsymshndx.c -@@ -90,7 +90,9 @@ gelf_getsymshndx (symdata, shndxdata, nd - section index table. */ - if (likely (shndxdata_scn != NULL)) - { -- if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Word) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Word) -+ > shndxdata_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -110,7 +112,8 @@ gelf_getsymshndx (symdata, shndxdata, nd - table entries has to be adopted. The user better has provided - a buffer where we can store the information. While copying the - data we are converting the format. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) -+ if (INVALID_NDX (ndx, Elf32_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -139,7 +142,8 @@ gelf_getsymshndx (symdata, shndxdata, nd - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) -+ if (INVALID_NDX (ndx, GElf_Sym) -+ || unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/elf32_newphdr.c.robustify -+++ elfutils-0.127/libelf/elf32_newphdr.c -@@ -124,6 +124,12 @@ elfw2(LIBELFBITS,newphdr) (elf, count) - else if (elf->state.ELFW(elf,LIBELFBITS).ehdr->e_phnum != count - || elf->state.ELFW(elf,LIBELFBITS).phdr == NULL) - { -+ if (unlikely (count > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Phdr)))) -+ { -+ result = NULL; -+ goto out; -+ } -+ - /* Allocate a new program header with the appropriate number of - elements. */ - result = (ElfW2(LIBELFBITS,Phdr) *) ---- elfutils-0.127/libelf/gelf_update_sym.c.robustify -+++ elfutils-0.127/libelf/gelf_update_sym.c -@@ -72,12 +72,6 @@ gelf_update_sym (data, ndx, src) - if (data == NULL) - return 0; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return 0; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_SYM)) - { - /* The type of the data better should match. */ -@@ -102,7 +96,8 @@ gelf_update_sym (data, ndx, src) - } - - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -125,7 +120,8 @@ gelf_update_sym (data, ndx, src) - else - { - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Sym) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_getsyminfo.c.robustify -+++ elfutils-0.127/libelf/gelf_getsyminfo.c -@@ -84,7 +84,8 @@ gelf_getsyminfo (data, ndx, dst) - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) -+ if (INVALID_NDX (ndx, GElf_Syminfo) -+ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_getlib.c.robustify -+++ elfutils-0.127/libelf/gelf_getlib.c -@@ -86,7 +86,8 @@ gelf_getlib (data, ndx, dst) - /* The data is already in the correct form. Just make sure the - index is OK. */ - GElf_Lib *result = NULL; -- if (unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) -+ if (INVALID_NDX (ndx, GElf_Lib) -+ || unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size)) - __libelf_seterrno (ELF_E_INVALID_INDEX); - else - { ---- elfutils-0.127/libelf/elf32_updatefile.c.robustify -+++ elfutils-0.127/libelf/elf32_updatefile.c -@@ -201,6 +201,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf - /* Write all the sections. Well, only those which are modified. */ - if (shnum > 0) - { -+ if (unlikely (shnum > SIZE_MAX / sizeof (Elf_Scn *))) -+ return 1; -+ - Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns; - Elf_Scn **scns = (Elf_Scn **) alloca (shnum * sizeof (Elf_Scn *)); - char *const shdr_start = ((char *) elf->map_address + elf->start_offset -@@ -571,6 +574,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf - /* Write all the sections. Well, only those which are modified. */ - if (shnum > 0) - { -+ if (unlikely (shnum > SIZE_MAX / (sizeof (Elf_Scn *) -+ + sizeof (ElfW2(LIBELFBITS,Shdr))))) -+ return 1; -+ - off_t shdr_offset = elf->start_offset + ehdr->e_shoff; - #if EV_NUM != 2 - xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR]; ---- elfutils-0.127/libelf/gelf_getversym.c.robustify -+++ elfutils-0.127/libelf/gelf_getversym.c -@@ -92,7 +92,8 @@ gelf_getversym (data, ndx, dst) - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) -+ if (INVALID_NDX (ndx, GElf_Versym) -+ || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - result = NULL; ---- elfutils-0.127/libelf/elf_getarsym.c.robustify -+++ elfutils-0.127/libelf/elf_getarsym.c -@@ -179,6 +179,9 @@ elf_getarsym (elf, ptr) - size_t index_size = atol (tmpbuf); - - if (SARMAG + sizeof (struct ar_hdr) + index_size > elf->maximum_size -+#if SIZE_MAX <= 4294967295U -+ || n >= SIZE_MAX / sizeof (Elf_Arsym) -+#endif - || n * sizeof (uint32_t) > index_size) - { - /* This index table cannot be right since it does not fit into ---- elfutils-0.127/libelf/gelf_getrel.c.robustify -+++ elfutils-0.127/libelf/gelf_getrel.c -@@ -71,12 +71,6 @@ gelf_getrel (data, ndx, dst) - if (data_scn == NULL) - return NULL; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return NULL; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_REL)) - { - __libelf_seterrno (ELF_E_INVALID_HANDLE); -@@ -93,7 +87,8 @@ gelf_getrel (data, ndx, dst) - if (scn->elf->class == ELFCLASS32) - { - /* We have to convert the data. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Rel) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - result = NULL; -@@ -113,7 +108,8 @@ gelf_getrel (data, ndx, dst) - { - /* Simply copy the data after we made sure we are actually getting - correct data. */ -- if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Rel) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - result = NULL; ---- elfutils-0.127/libelf/gelf_update_versym.c.robustify -+++ elfutils-0.127/libelf/gelf_update_versym.c -@@ -75,7 +75,7 @@ gelf_update_versym (data, ndx, src) - assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym)); - - /* Check whether we have to resize the data buffer. */ -- if (unlikely (ndx < 0) -+ if (INVALID_NDX (ndx, GElf_Versym) - || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); ---- elfutils-0.127/libelf/gelf_getdyn.c.robustify -+++ elfutils-0.127/libelf/gelf_getdyn.c -@@ -93,7 +93,8 @@ gelf_getdyn (data, ndx, dst) - table entries has to be adopted. The user better has provided - a buffer where we can store the information. While copying the - data we are converting the format. */ -- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf32_Dyn) -+ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; -@@ -114,7 +115,8 @@ gelf_getdyn (data, ndx, dst) - - /* The data is already in the correct form. Just make sure the - index is OK. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, GElf_Dyn) -+ || unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_update_syminfo.c.robustify -+++ elfutils-0.127/libelf/gelf_update_syminfo.c -@@ -72,12 +72,6 @@ gelf_update_syminfo (data, ndx, src) - if (data == NULL) - return 0; - -- if (unlikely (ndx < 0)) -- { -- __libelf_seterrno (ELF_E_INVALID_INDEX); -- return 0; -- } -- - if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO)) - { - /* The type of the data better should match. */ -@@ -93,7 +87,8 @@ gelf_update_syminfo (data, ndx, src) - rwlock_wrlock (scn->elf->lock); - - /* Check whether we have to resize the data buffer. */ -- if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, GElf_Syminfo) -+ || unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size)) - { - __libelf_seterrno (ELF_E_INVALID_INDEX); - goto out; ---- elfutils-0.127/libelf/gelf_update_rel.c.robustify -+++ elfutils-0.127/libelf/gelf_update_rel.c +--- elfutils-0.132/libelf/gelf_update_rel.c.robustify ++++ elfutils-0.132/libelf/gelf_update_rel.c @@ -68,12 +68,6 @@ gelf_update_rel (Elf_Data *dst, int ndx, if (dst == NULL) return 0; @@ -1399,31 +1454,20 @@ src/ { __libelf_seterrno (ELF_E_INVALID_INDEX); goto out; ---- elfutils-0.127/libelf/elf_newscn.c.robustify -+++ elfutils-0.127/libelf/elf_newscn.c -@@ -104,10 +104,18 @@ elf_newscn (elf) - else +--- elfutils-0.132/libelf/gelf_update_move.c.robustify ++++ elfutils-0.132/libelf/gelf_update_move.c +@@ -75,7 +75,7 @@ gelf_update_move (data, ndx, src) + assert (sizeof (GElf_Move) == sizeof (Elf64_Move)); + + /* Check whether we have to resize the data buffer. */ +- if (unlikely (ndx < 0) ++ if (INVALID_NDX (ndx, GElf_Move) + || unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size)) { - /* We must allocate a new element. */ -- Elf_ScnList *newp; -+ Elf_ScnList *newp = NULL; - - assert (elf->state.elf.scnincr > 0); - -+ if ( -+#if SIZE_MAX <= 4294967295U -+ likely (elf->state.elf.scnincr -+ < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList)) -+#else -+ 1 -+#endif -+ ) - newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList) - + ((elf->state.elf.scnincr *= 2) - * sizeof (Elf_Scn)), 1); ---- elfutils-0.127/libelf/gelf_update_lib.c.robustify -+++ elfutils-0.127/libelf/gelf_update_lib.c -@@ -68,12 +68,6 @@ gelf_update_lib (data, ndx, src) + __libelf_seterrno (ELF_E_INVALID_INDEX); +--- elfutils-0.132/libelf/gelf_update_dyn.c.robustify ++++ elfutils-0.132/libelf/gelf_update_dyn.c +@@ -71,12 +71,6 @@ gelf_update_dyn (data, ndx, src) if (data == NULL) return 0; @@ -1433,122 +1477,61 @@ src/ - return 0; - } - - Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data; - if (unlikely (data_scn->d.d_type != ELF_T_LIB)) + if (unlikely (data_scn->d.d_type != ELF_T_DYN)) { -@@ -87,7 +81,8 @@ gelf_update_lib (data, ndx, src) + /* The type of the data better should match. */ +@@ -102,7 +96,8 @@ gelf_update_dyn (data, ndx, src) + } - /* Check whether we have to resize the data buffer. */ - int result = 0; -- if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) -+ if (INVALID_NDX (ndx, Elf64_Lib) -+ || unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size)) - __libelf_seterrno (ELF_E_INVALID_INDEX); + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Dyn) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +@@ -116,7 +111,8 @@ gelf_update_dyn (data, ndx, src) else { ---- elfutils-0.127/libelf/elf_getshstrndx.c.robustify -+++ elfutils-0.127/libelf/elf_getshstrndx.c -@@ -125,10 +125,25 @@ elf_getshstrndx (elf, dst) - if (elf->map_address != NULL - && elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA - && (ALLOW_UNALIGNED -- || (((size_t) ((char *) elf->map_address + offset)) -+ || (((size_t) ((char *) elf->map_address -+ + elf->start_offset + offset)) - & (__alignof__ (Elf32_Shdr) - 1)) == 0)) -+ { -+ /* First see whether the information in the ELF header is -+ valid and it does not ask for too much. */ -+ if (unlikely (offset + sizeof (Elf32_Shdr) -+ > elf->maximum_size)) -+ { -+ /* Something is wrong. */ -+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); -+ result = -1; -+ goto out; -+ } -+ - /* We can directly access the memory. */ -- num = ((Elf32_Shdr *) (elf->map_address + offset))->sh_link; -+ num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset -+ + offset))->sh_link; -+ } - else - { - /* We avoid reading in all the section headers. Just read -@@ -163,10 +178,25 @@ elf_getshstrndx (elf, dst) - if (elf->map_address != NULL - && elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA - && (ALLOW_UNALIGNED -- || (((size_t) ((char *) elf->map_address + offset)) -+ || (((size_t) ((char *) elf->map_address -+ + elf->start_offset + offset)) - & (__alignof__ (Elf64_Shdr) - 1)) == 0)) -+ { -+ /* First see whether the information in the ELF header is -+ valid and it does not ask for too much. */ -+ if (unlikely (offset + sizeof (Elf64_Shdr) -+ > elf->maximum_size)) -+ { -+ /* Something is wrong. */ -+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); -+ result = -1; -+ goto out; -+ } -+ - /* We can directly access the memory. */ -- num = ((Elf64_Shdr *) (elf->map_address + offset))->sh_link; -+ num = ((Elf64_Shdr *) (elf->map_address -+ + elf->start_offset + offset))->sh_link; -+ } - else - { - /* We avoid reading in all the section headers. Just read ---- elfutils-0.127/libelf/elf32_getshdr.c.robustify -+++ elfutils-0.127/libelf/elf32_getshdr.c -@@ -101,7 +101,8 @@ elfw2(LIBELFBITS,getshdr) (scn) - goto out; - - size_t shnum; -- if (INTUSE (elf_getshnum) (elf, &shnum) != 0) -+ if (INTUSE (elf_getshnum) (elf, &shnum) != 0 -+ || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr))) - goto out; - size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr)); - -@@ -118,6 +119,16 @@ elfw2(LIBELFBITS,getshdr) (scn) - - if (elf->map_address != NULL) + /* Check whether we have to resize the data buffer. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Dyn) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size)) { -+ /* First see whether the information in the ELF header is -+ valid and it does not ask for too much. */ -+ if (unlikely (ehdr->e_shoff >= elf->maximum_size) -+ || unlikely (ehdr->e_shoff + size > elf->maximum_size)) -+ { -+ /* Something is wrong. */ -+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER); -+ goto free_and_out; -+ } -+ - ElfW2(LIBELFBITS,Shdr) *notcvt; + __libelf_seterrno (ELF_E_INVALID_INDEX); + goto out; +--- elfutils-0.132/libelf/gelf_getrela.c.robustify ++++ elfutils-0.132/libelf/gelf_getrela.c +@@ -71,12 +71,6 @@ gelf_getrela (data, ndx, dst) + if (data_scn == NULL) + return NULL; - /* All the data is already mapped. If we could use it ---- elfutils-0.127/libelf/elf32_getphdr.c.robustify -+++ elfutils-0.127/libelf/elf32_getphdr.c -@@ -116,6 +116,16 @@ elfw2(LIBELFBITS,getphdr) (elf) - - if (elf->map_address != NULL) +- if (unlikely (ndx < 0)) +- { +- __libelf_seterrno (ELF_E_INVALID_INDEX); +- return NULL; +- } +- + if (unlikely (data_scn->d.d_type != ELF_T_RELA)) + { + __libelf_seterrno (ELF_E_INVALID_HANDLE); +@@ -93,7 +87,8 @@ gelf_getrela (data, ndx, dst) + if (scn->elf->class == ELFCLASS32) + { + /* We have to convert the data. */ +- if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf32_Rela) ++ || unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size)) { -+ /* First see whether the information in the ELF header is -+ valid and it does not ask for too much. */ -+ if (unlikely (ehdr->e_phoff >= elf->maximum_size) -+ || unlikely (ehdr->e_phoff + size > elf->maximum_size)) -+ { -+ /* Something is wrong. */ -+ __libelf_seterrno (ELF_E_INVALID_PHDR); -+ goto out; -+ } -+ - /* All the data is already mapped. Use it. */ - void *file_phdr = ((char *) elf->map_address - + elf->start_offset + ehdr->e_phoff); + __libelf_seterrno (ELF_E_INVALID_INDEX); + result = NULL; +@@ -114,7 +109,8 @@ gelf_getrela (data, ndx, dst) + { + /* Simply copy the data after we made sure we are actually getting + correct data. */ +- if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) ++ if (INVALID_NDX (ndx, Elf64_Rela) ++ || unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size)) + { + __libelf_seterrno (ELF_E_INVALID_INDEX); + result = NULL; diff --git a/elfutils.spec b/elfutils.spec index 08bd0e5..f778e46 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,4 +1,4 @@ -%define eu_version 0.131 +%define eu_version 0.132 %define eu_release 1 %if %{?_with_compat:1}%{!?_with_compat:0} @@ -261,6 +261,15 @@ rm -rf ${RPM_BUILD_ROOT} %{_libdir}/libelf.a %changelog +* Mon Jan 21 2008 Roland McGrath - 0.132-1 +- Update to 0.132 + - libelf: Use loff_t instead of off64_t in libelf.h header. (#377241) + - eu-readelf: Fix handling of ET_REL files in archives. + - libcpu: Implement x86 and x86-64 disassembler. + - libasm: Add interface for disassembler. + - all programs: add debugging of branch prediction. + - libelf: new function elf_scnshndx. + * Sun Nov 11 2007 Roland McGrath - 0.131-1 - Update to 0.131 - libdw: DW_FORM_ref_addr support; dwarf_formref entry point now deprecated; diff --git a/sources b/sources index dd50480..5084895 100644 --- a/sources +++ b/sources @@ -1,3 +1,3 @@ 07a924423a05b1bf6d0f9fe8b35dbe6b testfile16.symtab.bz2 bd40d1aaca8eaf1c7aea54bf4b29bda2 testfile16.symtab.debug.bz2 -f7963fba80c6f74cd6c4990d2a76d121 elfutils-0.131.tar.gz +8e7f4d514fa11386fb83c572ee4e8830 elfutils-0.132.tar.gz