Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: src/processor/exploitability_unittest.cc

Issue 1697963002: Fixing a flaky Linux exploitability unittest. (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Fixing a typo. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010, Google Inc. 1 // Copyright (c) 2010, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 #ifndef _WIN32 40 #ifndef _WIN32
41 #include "processor/exploitability_linux.h" 41 #include "processor/exploitability_linux.h"
42 #endif // _WIN32 42 #endif // _WIN32
43 #include "processor/simple_symbol_supplier.h" 43 #include "processor/simple_symbol_supplier.h"
44 44
45 #ifndef _WIN32 45 #ifndef _WIN32
46 namespace google_breakpad { 46 namespace google_breakpad {
47 47
48 class ExploitabilityLinuxTest : public ExploitabilityLinux { 48 class ExploitabilityLinuxTest : public ExploitabilityLinux {
49 public: 49 public:
50 using ExploitabilityLinux::CalculateAddress;
50 using ExploitabilityLinux::DisassembleBytes; 51 using ExploitabilityLinux::DisassembleBytes;
52 using ExploitabilityLinux::GetObjdumpInstructionLine;
51 using ExploitabilityLinux::TokenizeObjdumpInstruction; 53 using ExploitabilityLinux::TokenizeObjdumpInstruction;
52 using ExploitabilityLinux::CalculateAddress;
53 }; 54 };
54 55
55 class ExploitabilityLinuxTestMinidumpContext : public MinidumpContext { 56 class ExploitabilityLinuxTestMinidumpContext : public MinidumpContext {
56 public: 57 public:
57 explicit ExploitabilityLinuxTestMinidumpContext( 58 explicit ExploitabilityLinuxTestMinidumpContext(
58 const MDRawContextAMD64& context) : MinidumpContext(NULL) { 59 const MDRawContextAMD64& context) : MinidumpContext(NULL) {
59 valid_ = true; 60 valid_ = true;
60 SetContextAMD64(new MDRawContextAMD64(context)); 61 SetContextAMD64(new MDRawContextAMD64(context));
61 SetContextFlags(MD_CONTEXT_AMD64); 62 SetContextFlags(MD_CONTEXT_AMD64);
62 } 63 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 buffer)); 194 buffer));
194 std::stringstream objdump_stream; 195 std::stringstream objdump_stream;
195 objdump_stream.str(string(buffer)); 196 objdump_stream.str(string(buffer));
196 string line = ""; 197 string line = "";
197 while (line.find("<.data>") == string::npos) 198 while (line.find("<.data>") == string::npos)
198 getline(objdump_stream, line); 199 getline(objdump_stream, line);
199 getline(objdump_stream, line); 200 getline(objdump_stream, line);
200 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5"); 201 ASSERT_EQ(line, " 0:\tc7 00 05 00 00 00 \tmov DWORD PTR [rax],0x5");
201 } 202 }
202 203
204 TEST(ExploitabilityLinuxUtilsTest, GetObjdumpInstructionLine) {
205 string disassebly =
206 "\n"
207 "/tmp/breakpad_mem_region-raw_bytes-tMmMo0: file format binary\n"
208 "// Trying to confuse the parser 0:\n"
209 "\n"
210 "Disassembly of section .data:\n"
211 "\n"
212 "0000000000000000 <.data>:\n"
213 " 0:\tc7 00 01 00 00 00 \tmov DWORD PTR [rax],0x1\n"
214 " 6:\t5d \tpop rbp\n"
215 " 7:\tc3 \tret \n"
216 " 8:\t55 \tpush rbp\n"
217 " 9:\t48 89 e5 \tmov rbp,rsp\n"
218 " c:\t53 \tpush rbx\n"
219 " d:\t48 \trex.W\n"
220 " e:\t81 \t.byte 0x81\n";
221 string line;
222 EXPECT_TRUE(ExploitabilityLinuxTest::GetObjdumpInstructionLine(
223 disassebly.c_str(), &line));
224 EXPECT_EQ(" 0:\tc7 00 01 00 00 00 \tmov DWORD PTR [rax],0x1", line);
225
226 // There is no "0:" after "<.data>:". Expected to return false.
227 disassebly =
228 "\n"
229 "/tmp/breakpad_mem_region-raw_bytes-tMmMo0: file format binary\n"
230 "// Trying to confuse the parser 0:\n"
231 "\n"
232 "Disassembly of section .data:\n"
233 "\n"
234 " 0:\tc7 00 01 00 00 00 \tmov DWORD PTR [rax],0x1\n"
235 " 6:\t5d \tpop rbp\n"
236 " 7:\tc3 \tret \n"
237 " 8:\t55 \tpush rbp\n"
238 " 9:\t48 89 e5 \tmov rbp,rsp\n"
239 " d:\t48 \trex.W\n"
240 "0000000000000000 <.data>:\n"
241 " c:\t53 \tpush rbx\n";
242 EXPECT_FALSE(ExploitabilityLinuxTest::GetObjdumpInstructionLine(
243 disassebly.c_str(), &line));
244 }
245
203 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) { 246 TEST(ExploitabilityLinuxUtilsTest, TokenizeObjdumpInstructionTest) {
204 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("", 247 ASSERT_FALSE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction("",
205 NULL, 248 NULL,
206 NULL, 249 NULL,
207 NULL)); 250 NULL));
208 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5"; 251 string line = "0: c7 00 05 00 00 00 mov DWORD PTR [rax],0x5";
209 string operation = ""; 252 string operation = "";
210 string dest = ""; 253 string dest = "";
211 string src = ""; 254 string src = "";
212 ASSERT_TRUE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction(line, 255 ASSERT_TRUE(ExploitabilityLinuxTest::TokenizeObjdumpInstruction(line,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax", 295 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("rdx+rax",
253 context, 296 context,
254 &write_address)); 297 &write_address));
255 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2", 298 ASSERT_FALSE(ExploitabilityLinuxTest::CalculateAddress("0x3482+0x4D2",
256 context, 299 context,
257 &write_address)); 300 &write_address));
258 } 301 }
259 #endif // _WIN32 302 #endif // _WIN32
260 303
261 } // namespace 304 } // namespace
OLDNEW
« src/processor/exploitability_linux.cc ('K') | « src/processor/exploitability_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698