diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/asan.cc | 15 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/asan/pr105714.c | 33 |
2 files changed, 47 insertions, 1 deletions
diff --git a/gcc/asan.cc b/gcc/asan.cc index 4b583e5..15b2cf8 100644 --- a/gcc/asan.cc +++ b/gcc/asan.cc @@ -1285,7 +1285,20 @@ has_stmt_been_instrumented_p (gimple *stmt) if (get_mem_ref_of_assignment (as_a <gassign *> (stmt), &r, &r_is_store)) - return has_mem_ref_been_instrumented (&r); + { + if (!has_mem_ref_been_instrumented (&r)) + return false; + if (r_is_store && gimple_assign_load_p (stmt)) + { + asan_mem_ref src; + asan_mem_ref_init (&src, NULL, 1); + src.start = gimple_assign_rhs1 (stmt); + src.access_size = int_size_in_bytes (TREE_TYPE (src.start)); + if (!has_mem_ref_been_instrumented (&src)) + return false; + } + return true; + } } else if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)) { diff --git a/gcc/testsuite/gcc.dg/asan/pr105714.c b/gcc/testsuite/gcc.dg/asan/pr105714.c new file mode 100644 index 0000000..d378b8a --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/pr105714.c @@ -0,0 +1,33 @@ +/* PR sanitizer/105714 */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-Os" } } */ +/* { dg-shouldfail "asan" } */ + +struct A { int x; }; +struct A b[2]; +struct A *c = b, *d = b; +int e; + +int +foo () +{ + for (e = 0; e < 1; e++) + { + int i[1]; + i; + } + for (int h = 0; h < 3; h++) + *c = *d; + *c = *(b + 3); + return c->x; +} + +int +main () +{ + foo (); + return 0; +} + +/* { dg-output "ERROR: AddressSanitizer: global-buffer-overflow on address.*(\n|\r\n|\r)" } */ +/* { dg-output "READ of size.*" } */ |