summaryrefslogtreecommitdiff
path: root/tests/stack_protector_test.cpp
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2013-01-16 13:13:22 -0800
committerNick Kralevich <nnk@google.com>2013-01-16 13:16:42 -0800
commit36bd371e26c716cbc18e11801b13eff0352d91b0 (patch)
treeb63e06f7a65f3ac2df09449bb65172644f230386 /tests/stack_protector_test.cpp
parentba117e4172fe6f160bf5f4d58b37e12c08c34245 (diff)
Revert "stack protector: use AT_RANDOM"
The AT_RANDOM changes broke setuid / setgid executables such as "ping". When the linker executes a setuid program, it cleans the environment, removing any invalid environment entries, and adding "NULL"s to the end of the environment array for each removed variable. Later on, we try to determine the location of the aux environment variable, and get tripped up by these extra NULLs. Reverting this patch will get setuid executables working again, but getauxval() is still broken for setuid programs because of this bug. This reverts commit e3a49a8661125f24aec8a1453e54b3b78005e21e. Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
Diffstat (limited to 'tests/stack_protector_test.cpp')
-rw-r--r--tests/stack_protector_test.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/tests/stack_protector_test.cpp b/tests/stack_protector_test.cpp
index ca90deac1..9cf3c38ab 100644
--- a/tests/stack_protector_test.cpp
+++ b/tests/stack_protector_test.cpp
@@ -56,7 +56,13 @@ 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);
@@ -72,7 +78,7 @@ static void* ThreadGuardHelper(void* arg) {
return NULL;
}
-TEST(stack_protector, same_guard_per_thread) {
+TEST(stack_protector, guard_per_thread) {
stack_protector_checker checker;
size_t thread_count = 10;
for (size_t i = 0; i < thread_count; ++i) {
@@ -84,8 +90,12 @@ TEST(stack_protector, same_guard_per_thread) {
}
ASSERT_EQ(thread_count, checker.tids.size());
- // bionic x86 and glibc uses the same guard for every thread.
+ // 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
ASSERT_EQ(1U, checker.guards.size());
+#endif
}
#endif