diff options
| author | Josh Gao <jmgao@google.com> | 2018-02-13 13:16:17 -0800 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2018-04-13 17:34:20 -0700 |
| commit | 2ac351b5c9707cfbb1d9fefa24710c005e8c7bfc (patch) | |
| tree | 6ade74f70af25a28e6164f287814de91c85530c1 | |
| parent | 96f5ddd85db28a35e0ee5271c32a9b4a5dce7929 (diff) | |
debuggerd: remove maximum abort message length.
Let the logging implementation be the imposer of limits.
Bug: http://b/64759619
Test: debuggerd_test
Change-Id: I8bc73bf2301ce071668993b740880224846a4e75
| -rw-r--r-- | debuggerd/debuggerd_test.cpp | 11 | ||||
| -rw-r--r-- | debuggerd/libdebuggerd/tombstone.cpp | 14 | ||||
| -rw-r--r-- | debuggerd/libdebuggerd/utility.cpp | 21 |
3 files changed, 27 insertions, 19 deletions
diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index 397ff2f116..e410be9101 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -354,7 +354,14 @@ TEST_F(CrasherTest, abort_message) { int intercept_result; unique_fd output_fd; StartProcess([]() { - android_set_abort_message("abort message goes here"); + // Arrived at experimentally; + // logd truncates at 4062. + // strlen("Abort message: ''") is 17. + // That's 4045, but we also want a NUL. + char buf[4045 + 1]; + memset(buf, 'x', sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; + android_set_abort_message(buf); abort(); }); StartIntercept(&output_fd); @@ -366,7 +373,7 @@ TEST_F(CrasherTest, abort_message) { std::string result; ConsumeFd(std::move(output_fd), &result); - ASSERT_MATCH(result, R"(Abort message: 'abort message goes here')"); + ASSERT_MATCH(result, R"(Abort message: 'x{4045}')"); } TEST_F(CrasherTest, abort_message_backtrace) { diff --git a/debuggerd/libdebuggerd/tombstone.cpp b/debuggerd/libdebuggerd/tombstone.cpp index 140ef6d23f..55d6204ac7 100644 --- a/debuggerd/libdebuggerd/tombstone.cpp +++ b/debuggerd/libdebuggerd/tombstone.cpp @@ -239,19 +239,23 @@ static void dump_abort_message(log_t* log, Memory* process_memory, uint64_t addr return; } - char msg[512]; - if (length >= sizeof(msg)) { - _LOG(log, logtype::HEADER, "Abort message too long: claimed length = %zd\n", length); + // The length field includes the length of the length field itself. + if (length < sizeof(size_t)) { + _LOG(log, logtype::HEADER, "Abort message header malformed: claimed length = %zd\n", length); return; } - if (!process_memory->ReadFully(address + sizeof(length), msg, length)) { + length -= sizeof(size_t); + + std::vector<char> msg(length); + if (!process_memory->ReadFully(address + sizeof(length), &msg[0], length)) { _LOG(log, logtype::HEADER, "Failed to read abort message: %s\n", strerror(errno)); return; } + // The abort message should be null terminated already, but just in case... msg[length] = '\0'; - _LOG(log, logtype::HEADER, "Abort message: '%s'\n", msg); + _LOG(log, logtype::HEADER, "Abort message: '%s'\n", &msg[0]); } static void dump_all_maps(log_t* log, BacktraceMap* map, Memory* process_memory, uint64_t addr) { diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp index d1538653d3..1ad1800736 100644 --- a/debuggerd/libdebuggerd/utility.cpp +++ b/debuggerd/libdebuggerd/utility.cpp @@ -74,25 +74,22 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) { && (log->crashed_tid == log->current_tid); static bool write_to_kmsg = should_write_to_kmsg(); - char buf[512]; + std::string msg; va_list ap; va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); + android::base::StringAppendV(&msg, fmt, ap); va_end(ap); - size_t len = strlen(buf); - if (len <= 0) { - return; - } + if (msg.empty()) return; if (write_to_tombstone) { - TEMP_FAILURE_RETRY(write(log->tfd, buf, len)); + TEMP_FAILURE_RETRY(write(log->tfd, msg.c_str(), msg.size())); } if (write_to_logcat) { - __android_log_buf_write(LOG_ID_CRASH, ANDROID_LOG_FATAL, LOG_TAG, buf); + __android_log_buf_write(LOG_ID_CRASH, ANDROID_LOG_FATAL, LOG_TAG, msg.c_str()); if (log->amfd_data != nullptr) { - *log->amfd_data += buf; + *log->amfd_data += msg; } if (write_to_kmsg) { @@ -100,11 +97,11 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) { if (kmsg_fd.get() >= 0) { // Our output might contain newlines which would otherwise be handled by the android logger. // Split the lines up ourselves before sending to the kernel logger. - if (buf[len - 1] == '\n') { - buf[len - 1] = '\0'; + if (msg.back() == '\n') { + msg.back() = '\0'; } - std::vector<std::string> fragments = android::base::Split(buf, "\n"); + std::vector<std::string> fragments = android::base::Split(msg, "\n"); for (const std::string& fragment : fragments) { static constexpr char prefix[] = "<3>DEBUG: "; struct iovec iov[3]; |
