Commit f41e5bd1 by Jakub Jelinek Committed by Jakub Jelinek

re PR bootstrap/55380 (All search_line_fast implementations read beyond buffer)

	PR bootstrap/55380
	PR other/54691
	* files.c (read_file_guts): Allocate extra 16 bytes instead of
	1 byte at the end of buf.  Pass size + 16 instead of size
	to _cpp_convert_input.
	* charset.c (_cpp_convert_input): Reallocate if there aren't
	at least 16 bytes beyond to.len in the buffer.  Clear 16 bytes
	at to.text + to.len.

From-SVN: r194102
parent 36402bb1
2012-12-03 Jakub Jelinek <jakub@redhat.com>
PR bootstrap/55380
PR other/54691
* files.c (read_file_guts): Allocate extra 16 bytes instead of
1 byte at the end of buf. Pass size + 16 instead of size
to _cpp_convert_input.
* charset.c (_cpp_convert_input): Reallocate if there aren't
at least 16 bytes beyond to.len in the buffer. Clear 16 bytes
at to.text + to.len.
2012-11-21 Steve Ellcey <sellcey@mips.com> 2012-11-21 Steve Ellcey <sellcey@mips.com>
PR pch/55399 PR pch/55399
......
/* CPP Library - charsets /* CPP Library - charsets
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009,
2010 Free Software Foundation, Inc. 2010, 2012 Free Software Foundation, Inc.
Broken out of c-lex.c Apr 2003, adding valid C99 UCN ranges. Broken out of c-lex.c Apr 2003, adding valid C99 UCN ranges.
...@@ -1729,9 +1729,15 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset, ...@@ -1729,9 +1729,15 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
iconv_close (input_cset.cd); iconv_close (input_cset.cd);
/* Resize buffer if we allocated substantially too much, or if we /* Resize buffer if we allocated substantially too much, or if we
haven't enough space for the \n-terminator. */ haven't enough space for the \n-terminator or following
if (to.len + 4096 < to.asize || to.len >= to.asize) 15 bytes of padding (used to quiet warnings from valgrind or
to.text = XRESIZEVEC (uchar, to.text, to.len + 1); Address Sanitizer, when the optimized lexer accesses aligned
16-byte memory chunks, including the bytes after the malloced,
area, and stops lexing on '\n'). */
if (to.len + 4096 < to.asize || to.len + 16 > to.asize)
to.text = XRESIZEVEC (uchar, to.text, to.len + 16);
memset (to.text + to.len, '\0', 16);
/* If the file is using old-school Mac line endings (\r only), /* If the file is using old-school Mac line endings (\r only),
terminate with another \r, not an \n, so that we do not mistake terminate with another \r, not an \n, so that we do not mistake
......
...@@ -671,7 +671,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) ...@@ -671,7 +671,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
the majority of C source files. */ the majority of C source files. */
size = 8 * 1024; size = 8 * 1024;
buf = XNEWVEC (uchar, size + 1); /* The + 16 here is space for the final '\n' and 15 bytes of padding,
used to quiet warnings from valgrind or Address Sanitizer, when the
optimized lexer accesses aligned 16-byte memory chunks, including
the bytes after the malloced, area, and stops lexing on '\n'. */
buf = XNEWVEC (uchar, size + 16);
total = 0; total = 0;
while ((count = read (file->fd, buf + total, size - total)) > 0) while ((count = read (file->fd, buf + total, size - total)) > 0)
{ {
...@@ -682,7 +686,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) ...@@ -682,7 +686,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
if (regular) if (regular)
break; break;
size *= 2; size *= 2;
buf = XRESIZEVEC (uchar, buf, size + 1); buf = XRESIZEVEC (uchar, buf, size + 16);
} }
} }
...@@ -699,7 +703,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file) ...@@ -699,7 +703,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
file->buffer = _cpp_convert_input (pfile, file->buffer = _cpp_convert_input (pfile,
CPP_OPTION (pfile, input_charset), CPP_OPTION (pfile, input_charset),
buf, size, total, buf, size + 16, total,
&file->buffer_start, &file->buffer_start,
&file->st.st_size); &file->st.st_size);
file->buffer_valid = true; file->buffer_valid = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment