summaryrefslogtreecommitdiff
path: root/tests/stack_protector_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-07 18:39:34 -0800
committerElliott Hughes <enh@google.com>2013-02-08 11:16:13 -0800
commitd3920b3a996b358e48232f417aa0a1e44a60f155 (patch)
treeb0520d0d300dbca1e6e54a9a7c26e6d2cd81ed08 /tests/stack_protector_test.cpp
parentf6afd3b670e23f56bf341d12136416aee17ea249 (diff)
Switch to using AT_RANDOM for the stack guards.
Bug: 7959813 Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
Diffstat (limited to 'tests/stack_protector_test.cpp')
-rw-r--r--tests/stack_protector_test.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index 9cf3c38ab..664a11e7b 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -56,13 +56,7 @@ struct stack_protector_checker {
// Duplicate tid. gettid(2) bug? Seeing this would be very upsetting.
ASSERT_TRUE(tids.find(tid) == tids.end());
-#ifdef __GLIBC__
- // glibc uses the same guard for every thread. bionic uses a different guard for each one.
-#else
- // Duplicate guard. Our bug. Note this is potentially flaky; we _could_ get the
- // same guard for two threads, but it should be vanishingly unlikely.
- ASSERT_TRUE(guards.find(guard) == guards.end());
-#endif
+
// Uninitialized guard. Our bug. Note this is potentially flaky; we _could_ get
// four random zero bytes, but it should be vanishingly unlikely.
ASSERT_NE(guard, 0U);
@@ -78,7 +72,7 @@ static void* ThreadGuardHelper(void* arg) {
return NULL;
}
-TEST(stack_protector, guard_per_thread) {
+TEST(stack_protector, same_guard_per_thread) {
stack_protector_checker checker;
size_t thread_count = 10;
for (size_t i = 0; i < thread_count; ++i) {
@@ -90,12 +84,8 @@ TEST(stack_protector, guard_per_thread) {
}
ASSERT_EQ(thread_count, checker.tids.size());
- // glibc uses the same guard for every thread. bionic uses a different guard for each one.
-#ifdef __BIONIC__
- ASSERT_EQ(thread_count, checker.guards.size());
-#else
+ // bionic and glibc use the same guard for every thread.
ASSERT_EQ(1U, checker.guards.size());
-#endif
}
#endif
@@ -107,11 +97,11 @@ TEST(stack_protector, guard_per_thread) {
// Bionic has the global for x86 too, to support binaries that can run on
// Android releases that didn't implement the TLS guard value.
-extern "C" void* __stack_chk_guard;
+extern "C" uintptr_t __stack_chk_guard;
TEST(stack_protector, global_guard) {
ASSERT_NE(0, gettid());
- ASSERT_NE(0U, reinterpret_cast<uintptr_t>(__stack_chk_guard));
+ ASSERT_NE(0U, __stack_chk_guard);
}
/*
@@ -124,7 +114,7 @@ TEST(stack_protector, global_guard) {
*/
__attribute__ ((noinline))
static void do_modify_stack_chk_guard() {
- __stack_chk_guard = (void *) 0x12345678;
+ __stack_chk_guard = 0x12345678;
}
// We have to say "DeathTest" here so gtest knows to run this test (which exits)