[ARM] Avoid dereferencing null pointers

Christophe Lyon christophe.lyon@linaro.org
Tue Oct 23 14:21:00 GMT 2018


Hi,

While building an ARM FDPIC toolchain with a compiler generating Thumb
code, I face a couple of null pointer dereferences in cmse_scan().

When browsing ld-uClibc.so.1, all the external symbols have no info in
sym_hashes (sym_hashes[X] == NULL), and when handling libgcc_s.so.1
for the 2nd time in the same command, sym_hashes == NULL.

I don't know why this doesn't happen with a compiler generating Arm
code (ie. why the symbol tables are handled differently), but the
attached small patch prevents the linker from crashing.

OK?

Thanks,

Christophe
-------------- next part --------------
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 9c61181..6ea348b 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -5939,7 +5939,16 @@ cmse_scan (bfd *input_bfd, struct elf32_arm_link_hash_table *htab,
 	}
       else
 	{
+	  /* No hash table, stop iterating.  */
+	  if (sym_hashes == NULL)
+	    break;
+
 	  cmse_hash = elf32_arm_hash_entry (sym_hashes[i - ext_start]);
+
+	  /* Avoid dereferencing if info is not present.  */
+	  if (cmse_hash == NULL)
+	    continue;
+
 	  sym_name = (char *) cmse_hash->root.root.root.string;
 
 	  /* Not a special symbol.  */
-------------- next part --------------
2018-10-23  Christophe Lyon  <christophe.lyon@linaro.org>

	* elf32-arm.c (cmse_scan): Avoid dereferencing NULL pointers.



More information about the Binutils mailing list