From 8affa48ac7c55ade04713654a22f1c56319b1195 Mon Sep 17 00:00:00 2001 From: Joel Anderson Date: Fri, 5 Jun 2020 11:11:03 +0100 Subject: [PATCH] Fix a potential infinite loop in the Windows resource parser. PR 26082 * mclex.c (yylex): Add test for an empty input stream. --- binutils/ChangeLog | 5 +++++ binutils/mclex.c | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 9bbebf56194..161d19174f1 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2020-06-05 Joel Anderson + + PR 26082 + * mclex.c (yylex): Add test for an empty input stream. + 2020-06-04 Stephen Casner * testsuite/binutils-all/pr25662-pdp11.s: Alternate source file diff --git a/binutils/mclex.c b/binutils/mclex.c index 7e0688b07bf..1b5d5c374f3 100644 --- a/binutils/mclex.c +++ b/binutils/mclex.c @@ -337,17 +337,19 @@ yylex (void) if (mclex_want_line) { start_token = input_stream_pos; + if (input_stream_pos[0] == 0) + return -1; if (input_stream_pos[0] == '.' && (input_stream_pos[1] == '\n' || (input_stream_pos[1] == '\r' && input_stream_pos[2] == '\n'))) - { - mclex_want_line = FALSE; - while (input_stream_pos[0] != 0 && input_stream_pos[0] != '\n') - ++input_stream_pos; - if (input_stream_pos[0] == '\n') - ++input_stream_pos; - return MCENDLINE; - } + { + mclex_want_line = FALSE; + while (input_stream_pos[0] != 0 && input_stream_pos[0] != '\n') + ++input_stream_pos; + if (input_stream_pos[0] == '\n') + ++input_stream_pos; + return MCENDLINE; + } while (input_stream_pos[0] != 0 && input_stream_pos[0] != '\n') ++input_stream_pos; if (input_stream_pos[0] == '\n') -- 2.30.2