Fixing a flaky Linux exploitability unittest.

BUG=https://code.google.com/p/chromium/issues/detail?id=584174
R=mmandlis@chromium.org

Review URL: https://codereview.chromium.org/1697963002 .
This commit is contained in:
Ivan Penkov 2016-02-16 11:46:04 -08:00
parent e132514d80
commit dee15c2547
3 changed files with 82 additions and 16 deletions

View file

@ -231,21 +231,10 @@ bool ExploitabilityLinux::EndedOnIllegalWrite(uint64_t instruction_ptr) {
MAX_OBJDUMP_BUFFER_LEN,
objdump_output_buffer);
// Put buffer data into stream to output line-by-line.
std::stringstream objdump_stream;
objdump_stream.str(string(objdump_output_buffer));
string line;
// Pipe each output line into the string until the string contains
// the first instruction from objdump.
// Loop until the line shows the first instruction or there are no lines left.
do {
if (!getline(objdump_stream, line)) {
BPLOG(INFO) << "Objdump instructions not found";
return false;
}
} while (line.find("0:") == string::npos);
// This first instruction contains the above substring.
if (!GetObjdumpInstructionLine(objdump_output_buffer, &line)) {
return false;
}
// Convert objdump instruction line into the operation and operands.
string instruction = "";
@ -399,6 +388,33 @@ bool ExploitabilityLinux::CalculateAddress(const string &address_expression,
return true;
}
// static
bool ExploitabilityLinux::GetObjdumpInstructionLine(
const char *objdump_output_buffer,
string *instruction_line) {
// Put buffer data into stream to output line-by-line.
std::stringstream objdump_stream;
objdump_stream.str(string(objdump_output_buffer));
// Pipe each output line into the string until the string contains the first
// instruction from objdump. All lines before the "<.data>:" section are
// skipped. Loop until the line shows the first instruction or there are no
// lines left.
bool data_section_seen = false;
do {
if (!getline(objdump_stream, *instruction_line)) {
BPLOG(INFO) << "Objdump instructions not found";
return false;
}
if (instruction_line->find("<.data>:") != string::npos) {
data_section_seen = true;
}
} while (!data_section_seen || instruction_line->find("0:") == string::npos);
// This first instruction contains the above substring.
return true;
}
bool ExploitabilityLinux::TokenizeObjdumpInstruction(const string &line,
string *operation,
string *dest,