summaryrefslogtreecommitdiff
path: root/tests/stack_protector_test_helper.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-04-01 14:51:10 -0700
committerElliott Hughes <enh@google.com>2016-04-01 20:08:03 -0700
commit6057d184f548a5f17e2c9467228d167243d9736a (patch)
treedba67c4a0127309ae81e4a86a72d3236bbd18256 /tests/stack_protector_test_helper.cpp
parent1e8958448a94753dec9c070ef011628c0b230d98 (diff)
Fix the stack-protector test for x86/x86-64.
Built for fugu this was working fine, but built for generic x86/x86-64 the compiler was (a) optimizing out all the stack writes and (b) inserting enough padding on x86-64 for the canary to be safely out of the way. While here, let's tighten up this test so we test that it's sufficient to only overwrite the buffer by one byte... (cherry-pick of 6f90c1ac59eb4e7811b7b0e408615049c935c0a9.) Bug: http://b/27815668 Change-Id: I80a646de4b30fd5c78df20fdaa7e3eb163585caf
Diffstat (limited to 'tests/stack_protector_test_helper.cpp')
-rw-r--r--tests/stack_protector_test_helper.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/stack_protector_test_helper.cpp b/tests/stack_protector_test_helper.cpp
index 34f3c7726..53a5e05de 100644
--- a/tests/stack_protector_test_helper.cpp
+++ b/tests/stack_protector_test_helper.cpp
@@ -19,6 +19,13 @@ __attribute__((noinline)) void modify_stack_protector_test() {
char buf[128];
// We can't use memset here because it's fortified, and we want to test
// the line of defense *after* that.
- char* p = buf;
- while ((p - buf) < static_cast<int>(sizeof(buf) + sizeof(void*))) *p++ = '\0';
+ // Without volatile, the generic x86/x86-64 targets don't write to the stack.
+ volatile char* p = buf;
+ int size = static_cast<int>(sizeof(buf) + 1);
+#if __x86_64__
+ // The generic x86-64 target leaves an 8-byte gap between `buf` and the stack guard.
+ // We only need to corrupt one byte though.
+ size += 8;
+#endif
+ while ((p - buf) < size) *p++ = '\0';
}