Hi!

As seen in the issue, we try to instrument a global variable that contains a 
string
constant. Following patch does not instrument in the size is variable (VLA).

Patch survives regression tests and bootstraps on x86_64-linux.
It's questionable whether the same situation can also happen in 
asan_finish_file:

      FOR_EACH_DEFINED_VARIABLE (vnode)
        if (TREE_ASM_WRITTEN (vnode->decl)
            && asan_protect_global (vnode->decl))
          asan_add_global (vnode->decl, TREE_TYPE (type), v);

?

Ready to be installed?
Thanks,
Martin
>From 341129d1277cacdee7bcd2129ad8282d9319b11d Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Fri, 3 Jun 2016 10:23:57 +0200
Subject: [PATCH] Do not instrument string cst w/ unknown decl size (PR
 sanitizer/71378)

gcc/ChangeLog:

2016-06-03  Martin Liska  <mli...@suse.cz>

	* asan.c (add_string_csts): Instrument just string csts with a
	known decl size.

gcc/testsuite/ChangeLog:

2016-06-03  Martin Liska  <mli...@suse.cz>

	* g++.dg/asan/pr71378.C: New test.
---
 gcc/asan.c                          |  6 ++++--
 gcc/testsuite/g++.dg/asan/pr71378.C | 11 +++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/asan/pr71378.C

diff --git a/gcc/asan.c b/gcc/asan.c
index 71095fb..0dae480 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2474,8 +2474,10 @@ add_string_csts (constant_descriptor_tree **slot,
       && TREE_ASM_WRITTEN (desc->value)
       && asan_protect_global (desc->value))
     {
-      asan_add_global (SYMBOL_REF_DECL (XEXP (desc->rtl, 0)),
-		       aascd->type, aascd->v);
+      tree symbol = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
+
+      if (tree_fits_uhwi_p (DECL_SIZE_UNIT (symbol)))
+	asan_add_global (symbol, aascd->type, aascd->v);
     }
   return 1;
 }
diff --git a/gcc/testsuite/g++.dg/asan/pr71378.C b/gcc/testsuite/g++.dg/asan/pr71378.C
new file mode 100644
index 0000000..166eae1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr71378.C
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+class A {
+public:
+  int GetLen();
+};
+class B {
+  A s_MDSPartIDStr;
+  void FillLoadPartitionInfo();
+};
+void B::FillLoadPartitionInfo() { char a[s_MDSPartIDStr.GetLen()] = "foo"; }
-- 
2.8.3

Reply via email to