diff options
author | Yao Chen <yaochen@google.com> | 2019-03-01 10:04:47 -0800 |
---|---|---|
committer | Yao Chen <yaochen@google.com> | 2019-03-04 14:28:30 -0800 |
commit | b5908aedc0fdcf47a2f73f7e04eccd2e99a66357 (patch) | |
tree | 72f5d9a3f6895415c8af1937253ee103d5ef053e /cmds/incident_helper/src | |
parent | 65c6cd861860a719f1225730d0e3d57a531e6f1c (diff) |
Fix incident_helper crash.
The header of top cmd changes from Tasks to Threads, causing the parser to run into
undefined behavior.
Bug: 125377622
Test: adb shell dumpsys incident && incident_helper_test
Change-Id: I5ae88767dce22f0ee7b49611b2f19889a07e66ac
Diffstat (limited to 'cmds/incident_helper/src')
-rw-r--r-- | cmds/incident_helper/src/ih_util.cpp | 2 | ||||
-rw-r--r-- | cmds/incident_helper/src/parsers/CpuInfoParser.cpp | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/cmds/incident_helper/src/ih_util.cpp b/cmds/incident_helper/src/ih_util.cpp index 012310cc277a..77a56e55045b 100644 --- a/cmds/incident_helper/src/ih_util.cpp +++ b/cmds/incident_helper/src/ih_util.cpp @@ -142,7 +142,7 @@ record_t parseRecordByColumns(const std::string& line, const std::vector<int>& i } if (lineSize - lastIndex > 0) { int beginning = lastIndex; - if (record.size() == indices.size()) { + if (record.size() == indices.size() && !record.empty()) { // We've already encountered all of the columns...put whatever is // left in the last column. record.pop_back(); diff --git a/cmds/incident_helper/src/parsers/CpuInfoParser.cpp b/cmds/incident_helper/src/parsers/CpuInfoParser.cpp index 21ced9cb485c..5d525e6c7f3e 100644 --- a/cmds/incident_helper/src/parsers/CpuInfoParser.cpp +++ b/cmds/incident_helper/src/parsers/CpuInfoParser.cpp @@ -65,8 +65,9 @@ CpuInfoParser::Parse(const int in, const int out) const if (line.empty()) continue; nline++; - - if (stripPrefix(&line, "Tasks:")) { + // The format changes from time to time in toybox/toys/posix/ps.c + // With -H, it prints Threads instead of Tasks (FLAG(H)?"Thread":"Task") + if (stripPrefix(&line, "Threads:")) { writeSuffixLine(&proto, CpuInfoProto::TASK_STATS, line, COMMA_DELIMITER, CpuInfoProto::TaskStats::_FIELD_COUNT, CpuInfoProto::TaskStats::_FIELD_NAMES, |