Commit: Fix potential null pointer dereference in linker

Nick Clifton nickc@redhat.com
Thu Nov 21 17:02:00 GMT 2019


Hi Guys,

  I am applying the patch below to fix a potential null pointer
  dereference in the linker.  This also fixes an annoying message from
  the undefined behaviour sanitizer...

Cheers
  Nick

ld/ChangeLog
2019-11-21  Nick Clifton  <nickc@redhat.com>

	* ldlang.h (LANG_FOR_EACH_INPUT_STATEMENT): Check for an empty
	file chain before examining the first input statement.

diff --git a/ld/ldlang.h b/ld/ldlang.h
index 8cc5cf7f90..3e3e6a0289 100644
--- a/ld/ldlang.h
+++ b/ld/ldlang.h
@@ -574,7 +574,7 @@ extern asection *section_for_dot
 
 #define LANG_FOR_EACH_INPUT_STATEMENT(statement)			\
   lang_input_statement_type *statement;					\
-  for (statement = &file_chain.head->input_statement;			\
+  for (statement = file_chain.head == NULL ? NULL : &file_chain.head->input_statement; \
        statement != NULL;						\
        statement = statement->next)
 



More information about the Binutils mailing list