[binutils-gdb] Fix the windmc program to conform to the behaviour of mc.exe by rejecting lines that reach end-of-fi

Nick Clifton nickc@sourceware.org
Wed Jun 10 09:08:29 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=25065fcd192d9958c03e107985aea41d651e4a16

commit 25065fcd192d9958c03e107985aea41d651e4a16
Author: Ralf Habacker <ralf.habacker@freenet.de>
Date:   Wed Jun 10 10:07:26 2020 +0100

    Fix the windmc program to conform to the behaviour of mc.exe by rejecting lines that reach end-of-file without a terminating newline character.
    
            PR 26082
            * mclex.c (yylex): Reject lines that reach end-of-file without a
            terminating newline character.

Diff:
---
 binutils/ChangeLog |  6 ++++++
 binutils/mclex.c   | 38 +++++++++++++++++++++++++-------------
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index ec5b2ef2b7c..43eabaa0441 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2020-06-10  Ralf Habacker  <ralf.habacker@freenet.de>
+
+	PR 26082
+	* mclex.c (yylex): Reject lines that reach end-of-file without a
+	terminating newline character.
+
 2020-06-08  Nick Clifton  <nickc@redhat.com>
 
 	PR 26093
diff --git a/binutils/mclex.c b/binutils/mclex.c
index 1b5d5c374f3..da8bfb51311 100644
--- a/binutils/mclex.c
+++ b/binutils/mclex.c
@@ -323,6 +323,21 @@ mc_token (const unichar *t, size_t len)
   return -1;
 }
 
+/* Skip characters in input_stream_pos up to and including a newline
+   character.  Returns non-zero if the newline was found, zero otherwise.  */
+
+static int
+skip_until_eol (void)
+{
+  while (input_stream_pos[0] != 0 && input_stream_pos[0] != '\n')
+    ++input_stream_pos;
+  if (input_stream_pos[0] == 0)
+    return 0;
+  if (input_stream_pos[0] == '\n')
+    ++input_stream_pos;
+  return 1;
+}
+
 int
 yylex (void)
 {
@@ -334,29 +349,28 @@ yylex (void)
       fatal ("Input stream not setuped.\n");
       return -1;
     }
+
   if (mclex_want_line)
     {
       start_token = input_stream_pos;
       if (input_stream_pos[0] == 0)
 	return -1;
+      /* PR 26082: Reject a period followed by EOF.  */
+      if (input_stream_pos[0] == '.' && input_stream_pos[1] == 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;
+          return skip_until_eol () ? MCENDLINE : -1;
 	}
-      while (input_stream_pos[0] != 0 && input_stream_pos[0] != '\n')
-	++input_stream_pos;
-      if (input_stream_pos[0] == '\n')
-	++input_stream_pos;
+      if (!skip_until_eol ())
+	return -1;
       yylval.ustr = get_diff (input_stream_pos, start_token);
       return MCLINE;
     }
+
   while ((ch = input_stream_pos[0]) <= 0x20)
     {
       if (ch == 0)
@@ -404,10 +418,8 @@ yylex (void)
   {
   case ';':
     ++start_token;
-    while (input_stream_pos[0] != '\n' && input_stream_pos[0] != 0)
-      ++input_stream_pos;
-    if (input_stream_pos[0] == '\n')
-      input_stream_pos++;
+    if (!skip_until_eol ())
+      return -1;
     yylval.ustr = get_diff (input_stream_pos, start_token);
     return MCCOMMENT;
   case '=':


More information about the Binutils-cvs mailing list