[PATCH] check for invalid PPC relocation types
Nathan Froyd
froydnj@codesourcery.com
Mon Jun 25 18:28:00 GMT 2007
The attached patch fixes an error on PPC when objects contain invalid
relocation types. Previously, we would happily "return" a NULL
reloc_howto_type from ppc_elf_info_to_howto for an invalid relocation
type. Doing this would cause problems later down the line when
unsuspecting code would attempt to peek at members of NULL.
The fix is to check to see whether we were asked to describe an invalid
relocation type and, if so, simply use R_PPC_NONE and issue an error
message. This is similar to what the i386 backend already does.
Compiled and regtested on powerpc64-unknown-linux-gnu with no
regressions. OK?
-Nathan
bfd/
2007-06-25 Nathan Froyd <froydnj@codesourcery.com>
* elf32-ppc.c (ppc_elf_info_to_howto): Check for invalid relocation
types.
-------------- next part --------------
Index: bfd/elf32-ppc.c
===================================================================
--- bfd/elf32-ppc.c (revision 174845)
+++ bfd/elf32-ppc.c (working copy)
@@ -1607,6 +1607,17 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBU
BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
+
+ /* Just because the above assert didn't trigger doesn't mean that
+ ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
+ if (!cache_ptr->howto)
+ {
+ (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
+ abfd, ELF32_R_TYPE (dst->r_info));
+ bfd_set_error (bfd_error_bad_value);
+
+ cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
+ }
}
/* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
More information about the Binutils
mailing list