lexer: Fix details of journaling.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 6 Oct 2018 22:12:07 +0000 (15:12 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 6 Oct 2018 22:12:29 +0000 (15:12 -0700)
This fixes test 1075: ASCII driver syntax printback.

Reported by John Darrington and Jeremy Lavergne.
Fixes: b4f585e70eca ("lexer: Fix buffer overread in journaling when source does not end in \n.")
Fixes: e0f9210e814d ("lexer: Add support for embedded \0 bytes and missing trailing new-line.")
src/language/lexer/lexer.c

index 98cf8ec298245dfc53caf68648be4169a4cf90b0..36680f52bca43f2b85aa493ce77b539e8adf76b6 100644 (file)
@@ -1417,8 +1417,13 @@ lex_source_get__ (const struct lex_source *src_)
       /* Beginning of line. */
       const char *line = &src->buffer[src->journal_pos - src->tail];
 
-      /* Calculate line length, including \n or \r\n end-of-line if present. */
-      size_t max_len = state.line_pos - src->journal_pos;
+      /* Calculate line length, including \n or \r\n end-of-line if present.
+
+         We use src->head even though that may be beyond what we've actually
+         converted to tokens (which is only through state.line_pos).  That's
+         because, if we're emitting the line due to SEG_END_COMMAND, we want to
+         take the whole line through the newline, not just through the '.'. */
+      size_t max_len = src->head - src->journal_pos;
       const char *newline = memchr (line, '\n', max_len);
       size_t line_len = newline ? newline - line + 1 : max_len;