public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Allocate extra 16 bytes for -fsanitize=address
@ 2012-11-23 17:23 H.J. Lu
  2012-11-23 17:39 ` Jakub Jelinek
  0 siblings, 1 reply; 14+ messages in thread
From: H.J. Lu @ 2012-11-23 17:23 UTC (permalink / raw)
  To: gcc-patches

Hi,

This patch allocates extra 16 bytes for -fsanitize=address so that
asan won't report read beyond memory buffer. It is used by
bootstrap-asan.  OK to install?

Thanks.


H.J.
---
2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>

	PR bootstrap/55380
	* charset.c (_cpp_convert_input): Allocate extra 16 bytes for
	-fsanitize=address if __SANITIZE_ADDRESS__ is defined.

diff --git a/libcpp/charset.c b/libcpp/charset.c
index cba19a6..dea8bb1 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1729,9 +1729,16 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
     iconv_close (input_cset.cd);
 
   /* 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.  Allocate extra 16
+     bytes for -fsanitize=address.  */
   if (to.len + 4096 < to.asize || to.len >= to.asize)
-    to.text = XRESIZEVEC (uchar, to.text, to.len + 1);
+    {
+#ifdef __SANITIZE_ADDRESS__
+      to.text = XRESIZEVEC (uchar, to.text, to.len + 17);
+#else
+      to.text = XRESIZEVEC (uchar, to.text, to.len + 1);
+#endif
+    }
 
   /* 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
-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Re: [PATCH] Allocate extra 16 bytes for -fsanitize=address
@ 2012-11-23 19:01 Uros Bizjak
  2012-11-23 19:17 ` H.J. Lu
  0 siblings, 1 reply; 14+ messages in thread
From: Uros Bizjak @ 2012-11-23 19:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

Hello!

> This patch allocates extra 16 bytes for -fsanitize=address so that
> asan won't report read beyond memory buffer. It is used by
> bootstrap-asan.  OK to install?

   /* 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.  Allocate extra 16
+     bytes for -fsanitize=address.  */

I guess that extra _15_ bytes should be enough? The maximum we need
for SSE stringops is additional 15 bytes, when only the first byte is
allocated in the 16byte bundle.

Uros,

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-12-03 15:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-23 17:23 [PATCH] Allocate extra 16 bytes for -fsanitize=address H.J. Lu
2012-11-23 17:39 ` Jakub Jelinek
2012-11-23 18:08   ` H.J. Lu
2012-11-23 18:12     ` Jakub Jelinek
2012-11-23 18:17       ` H.J. Lu
2012-11-23 18:12     ` Konstantin Serebryany
2012-11-24 10:52     ` Hans-Peter Nilsson
2012-11-23 19:01 Uros Bizjak
2012-11-23 19:17 ` H.J. Lu
2012-11-23 19:23   ` Uros Bizjak
2012-11-23 19:33     ` H.J. Lu
2012-11-23 19:50       ` Jakub Jelinek
2012-11-26 14:50         ` H.J. Lu
2012-12-03 15:45         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).