Skip to content

Commit 00e0171

Browse files
committed
coredump: avoid relying on whitespace in header
JIRA: RTOS-1062
1 parent 398402d commit 00e0171

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

coredump_parser/parser.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sstream>
88
#include <string>
99
#include <vector>
10+
#include <algorithm>
1011

1112
enum class ParseStatus : int {
1213
Success = 0,
@@ -166,19 +167,21 @@ ParseStatus watch_stdin(std::vector<uint8_t> &data, additional_info &info)
166167
if (line.find("_COREDUMP_START_") != std::string::npos) {
167168
data.clear();
168169

169-
do {
170-
std::getline(std::cin, line);
171-
} while (line.empty());
172-
173-
auto pos = line.find(": ");
174-
if (pos == std::string::npos) {
175-
std::cerr << "Error: Missing process and exception in first line!"
170+
if (!std::getline(std::cin, line, ':')) {
171+
std::cerr << "Error: Missing first line with process and exception!"
176172
<< std::endl;
177173
return ParseStatus::CoredumpCorrupted;
178174
}
175+
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
176+
info.process_name = line;
179177

180-
info.process_name = line.substr(0, pos);
181-
info.exception = line.substr(pos + 2);
178+
if (!std::getline(std::cin, line, ';')) {
179+
std::cerr << "Error: Missing first line with process and exception!"
180+
<< std::endl;
181+
return ParseStatus::CoredumpCorrupted;
182+
}
183+
line.erase(std::remove(line.begin(), line.end(), '\n'), line.end());
184+
info.exception = line;
182185

183186
return read_decode(data, info.crc32);
184187
}

0 commit comments

Comments
 (0)