From b52696f9e567da157b152ae641f064507f993969 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Thu, 21 Nov 2019 17:02:40 +0000 Subject: [PATCH] Fix potentially undefined behaviour in the linker when parsing input statements. * ldlang.h (LANG_FOR_EACH_INPUT_STATEMENT): Check for an empty file chain before examining the first input statement. --- ld/ChangeLog | 5 +++++ ld/ldlang.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index e4e3f740584..5a3b2ddd1ca 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,8 @@ +2019-11-21 Nick Clifton + + * ldlang.h (LANG_FOR_EACH_INPUT_STATEMENT): Check for an empty + file chain before examining the first input statement. + 2019-11-21 Alan Modra PR 46 diff --git a/ld/ldlang.h b/ld/ldlang.h index 8cc5cf7f900..3e3e6a02894 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) -- 2.47.2