diff libinterp/parse-tree/lex.ll @ 23786:10136bfd46a3

lex.ll: Fix heap-buffer-overflow (bug #51533). * lex.ll (lexer::fill_flex_buffer): Check that string is non-empty before looking at last character to see if it is a newline.
author Rik <rik@octave.org>
date Sun, 23 Jul 2017 20:51:24 -0700
parents ea879bc55272
children b481a9baeb61
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll	Sun Jul 23 18:34:40 2017 -0700
+++ b/libinterp/parse-tree/lex.ll	Sun Jul 23 20:51:24 2017 -0700
@@ -3662,9 +3662,12 @@
 
         if (buffer_function_text)
           {
-            function_text += current_input_line;
-            if (current_input_line[current_input_line.length () - 1] != '\n')
-              function_text += "\n";
+            if (! current_input_line.empty ())
+            {
+              function_text += current_input_line;
+              if (current_input_line.back () != '\n')
+                function_text += "\n";
+            }
           }
       }