changeset 4146:cd7af18fb113

6341667 elfdump should check alignments of ELF header elements 6387860 elfdump cores, when processing linux built ELF file
author ab196087
date Tue, 01 May 2007 09:05:43 -0700
parents 90dc07a3821d
children ff1dcb77f31e
files usr/src/cmd/sgs/elfdump/common/elfdump.c usr/src/cmd/sgs/elfdump/common/elfdump.msg usr/src/cmd/sgs/packages/common/SUNWonld-README
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.c	Tue May 01 05:33:55 2007 -0700
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.c	Tue May 01 09:05:43 2007 -0700
@@ -2584,7 +2584,7 @@
 			/*
 			 * Only pay attention to relocations against the GOT.
 			 */
-			if ((offset < gotbgn) || (offset > gotend))
+			if ((offset < gotbgn) || (offset >= gotend))
 				continue;
 
 			/* LINTED */
@@ -2697,6 +2697,17 @@
 		Elf_ehdr(0, ehdr, shdr);
 
 	/*
+	 * If the section headers or program headers have inadequate
+	 * alignment for the class of object, print a warning. libelf
+	 * can handle such files, but programs that use them can crash
+	 * when they dereference unaligned items.
+	 */
+	if (ehdr->e_phoff & (sizeof (Addr) - 1))
+		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADPHDRALIGN), file);
+	if (ehdr->e_shoff & (sizeof (Addr) - 1))
+		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHDRALIGN), file);
+
+	/*
 	 * Print the program headers.
 	 */
 	if ((flags & FLG_PHDR) && (phnum != 0)) {
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.msg	Tue May 01 05:33:55 2007 -0700
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.msg	Tue May 01 09:05:43 2007 -0700
@@ -73,6 +73,8 @@
 @ MSG_ERR_BADREL1       "%s: bad relocation entry: %s: relocation requires symbol\n"
 @ MSG_ERR_SHSTRNULL	"%s: zero size section header string table (shstrtab)\n"
 @ MSG_ERR_FAILURE	"%s: %s failed: %s\n"
+@ MSG_ERR_BADSHDRALIGN	"%s: bad section header array alignment\n"
+@ MSG_ERR_BADPHDRALIGN	"%s: bad program header array alignment\n"
 @ MSG_ERR_BADSHNAME	"%s: section[%d]: invalid sh_name: %lld\n"
 @ MSG_ERR_BADSHLINK	"%s: %s: invalid sh_link: %d\n"
 @ MSG_ERR_BADSHINFO	"%s: %s: invalid sh_info: %d\n"
--- a/usr/src/cmd/sgs/packages/common/SUNWonld-README	Tue May 01 05:33:55 2007 -0700
+++ b/usr/src/cmd/sgs/packages/common/SUNWonld-README	Tue May 01 09:05:43 2007 -0700
@@ -1229,3 +1229,5 @@
 6541004 hwcap filter processing can leak memory
 5108874 elfdump SEGVs on bad object file
 6547441 Uninitialized variable causes ld.so.1 to crash on object cleanup
+6341667 elfdump should check alignments of ELF header elements
+6387860 elfdump cores, when processing linux built ELF file