diff options
author | Josh Gao <jmgao@google.com> | 2017-01-23 12:05:35 -0800 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2017-01-23 14:13:36 -0800 |
commit | fca7ca35850438230428a0018d7b933f7c8a847c (patch) | |
tree | 924dcec32180e1e3204362782ad434bd9eecef3f /debuggerd/debuggerd_test.cpp | |
parent | 400973fa8840fe50150797a83416c26e4828310a (diff) | |
download | system_core-fca7ca35850438230428a0018d7b933f7c8a847c.tar.gz system_core-fca7ca35850438230428a0018d7b933f7c8a847c.tar.bz2 system_core-fca7ca35850438230428a0018d7b933f7c8a847c.zip |
debuggerd_handler: properly crash when PR_GET_DUMPABLE is 0.
Actually exit when receiving a signal via kill(2) or raise(2) and
PR_GET_DUMPABLE is 0.
Bug: none
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests --gtest_filter=pthread_DeathTest.pthread_mutex_lock_null_64
Change-Id: I833a2a34238129237bd9f953959ebda51d8d04d7
Diffstat (limited to 'debuggerd/debuggerd_test.cpp')
-rw-r--r-- | debuggerd/debuggerd_test.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index 3b2419365..e7503e97e 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -17,6 +17,7 @@ #include <err.h> #include <fcntl.h> #include <unistd.h> +#include <sys/prctl.h> #include <sys/types.h> #include <chrono> @@ -90,6 +91,7 @@ class CrasherTest : public ::testing::Test { // Returns -1 if we fail to read a response from tombstoned, otherwise the received return code. void FinishIntercept(int* result); + void StartProcess(std::function<void()> function); void StartCrasher(const std::string& crash_type); void FinishCrasher(); void AssertDeath(int signo); @@ -166,9 +168,8 @@ void CrasherTest::FinishIntercept(int* result) { } } -void CrasherTest::StartCrasher(const std::string& crash_type) { - std::string type = "wait-" + crash_type; - +void CrasherTest::StartProcess(std::function<void()> function) { + unique_fd read_pipe; unique_fd crasher_read_pipe; if (!Pipe(&crasher_read_pipe, &crasher_pipe)) { FAIL() << "failed to create pipe: " << strerror(errno); @@ -182,9 +183,17 @@ void CrasherTest::StartCrasher(const std::string& crash_type) { dup2(crasher_read_pipe.get(), STDIN_FILENO); dup2(devnull.get(), STDOUT_FILENO); dup2(devnull.get(), STDERR_FILENO); + function(); + _exit(0); + } +} + +void CrasherTest::StartCrasher(const std::string& crash_type) { + std::string type = "wait-" + crash_type; + StartProcess([type]() { execl(CRASHER_PATH, CRASHER_PATH, type.c_str(), nullptr); err(1, "exec failed"); - } + }); } void CrasherTest::FinishCrasher() { @@ -379,3 +388,20 @@ TEST_F(CrasherTest, backtrace) { ConsumeFd(std::move(output_fd), &result); ASSERT_MATCH(result, R"(#00 pc [0-9a-f]+\s+ /system/lib)" ARCH_SUFFIX R"(/libc.so \(tgkill)"); } + +TEST_F(CrasherTest, PR_SET_DUMPABLE_0_crash) { + StartProcess([]() { + prctl(PR_SET_DUMPABLE, 0); + volatile char* null = static_cast<char*>(nullptr); + *null = '\0'; + }); + AssertDeath(SIGSEGV); +} + +TEST_F(CrasherTest, PR_SET_DUMPABLE_0_raise) { + StartProcess([]() { + prctl(PR_SET_DUMPABLE, 0); + raise(SIGUSR1); + }); + AssertDeath(SIGUSR1); +} |