/thirdparty/breakpad/processor/exploitability_unittest.cc

http://github.com/tomahawk-player/tomahawk · C++ · 255 lines · 181 code · 35 blank · 39 comment · 1 complexity · d9d14a8b8941975efcfdd56ddf6a69b9 MD5 · raw file

  1. // All rights reserved.
  2. //
  3. // Redistribution and use in source and binary forms, with or without
  4. // modification, are permitted provided that the following conditions are
  5. // met:
  6. //
  7. // * Redistributions of source code must retain the above copyright
  8. // notice, this list of conditions and the following disclaimer.
  9. // * Redistributions in binary form must reproduce the above
  10. // copyright notice, this list of conditions and the following disclaimer
  11. // in the documentation and/or other materials provided with the
  12. // distribution.
  13. // * Neither the name of Google Inc. nor the names of its
  14. // contributors may be used to endorse or promote products derived from
  15. // this software without specific prior written permission.
  16. //
  17. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE//
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. #include <stdlib.h>
  40. #include <unistd.h>
  41. #include <string>
  42. #include "breakpad_googletest_includes.h"
  43. #include "google_breakpad/processor/basic_source_line_resolver.h"
  44. #include "google_breakpad/processor/call_stack.h"
  45. #include "google_breakpad/processor/code_module.h"
  46. #include "google_breakpad/processor/code_modules.h"
  47. #include "google_breakpad/processor/minidump.h"
  48. #include "google_breakpad/processor/minidump_processor.h"
  49. #include "google_breakpad/processor/process_state.h"
  50. #include "google_breakpad/processor/stack_frame.h"
  51. #include "google_breakpad/processor/symbol_supplier.h"
  52. namespace google_breakpad {
  53. class MockMinidump : public Minidump {
  54. public:
  55. MockMinidump() : Minidump("") {
  56. }
  57. MOCK_METHOD0(Read, bool());
  58. MOCK_CONST_METHOD0(path, string());
  59. MOCK_CONST_METHOD0(header, const MDRawHeader*());
  60. MOCK_METHOD0(GetThreadList, MinidumpThreadList*());
  61. };
  62. }
  63. namespace {
  64. using google_breakpad::BasicSourceLineResolver;
  65. using google_breakpad::CallStack;
  66. using google_breakpad::CodeModule;
  67. using google_breakpad::MinidumpProcessor;
  68. using google_breakpad::MinidumpThreadList;
  69. using google_breakpad::MinidumpThread;
  70. using google_breakpad::MockMinidump;
  71. using google_breakpad::ProcessState;
  72. using google_breakpad::SymbolSupplier;
  73. using google_breakpad::SystemInfo;
  74. using std::string;
  75. class TestSymbolSupplier : public SymbolSupplier {
  76. public:
  77. TestSymbolSupplier() : interrupt_(false) {}
  78. virtual SymbolResult GetSymbolFile(const CodeModule *module,
  79. const SystemInfo *system_info,
  80. string *symbol_file);
  81. virtual SymbolResult GetSymbolFile(const CodeModule *module,
  82. const SystemInfo *system_info,
  83. string *symbol_file,
  84. string *symbol_data);
  85. virtual SymbolResult GetCStringSymbolData(const CodeModule *module,
  86. const SystemInfo *system_info,
  87. string *symbol_file,
  88. char **symbol_data);
  89. virtual void FreeSymbolData(const CodeModule *module) { }
  90. // When set to true, causes the SymbolSupplier to return INTERRUPT
  91. void set_interrupt(bool interrupt) { interrupt_ = interrupt; }
  92. private:
  93. bool interrupt_;
  94. };
  95. SymbolSupplier::SymbolResult TestSymbolSupplier::GetSymbolFile(
  96. const CodeModule *module,
  97. const SystemInfo *system_info,
  98. string *symbol_file) {
  99. if (interrupt_) {
  100. return INTERRUPT;
  101. }
  102. return NOT_FOUND;
  103. }
  104. SymbolSupplier::SymbolResult TestSymbolSupplier::GetCStringSymbolData(
  105. const CodeModule *module,
  106. const SystemInfo *system_info,
  107. string *symbol_file,
  108. char **symbol_data) {
  109. return GetSymbolFile(module, system_info, symbol_file);
  110. }
  111. SymbolSupplier::SymbolResult TestSymbolSupplier::GetSymbolFile(
  112. const CodeModule *module,
  113. const SystemInfo *system_info,
  114. string *symbol_file,
  115. string *symbol_data) {
  116. return GetSymbolFile(module, system_info, symbol_file);
  117. }
  118. TEST(ExploitabilityTest, TestWindowsEngine) {
  119. TestSymbolSupplier supplier;
  120. BasicSourceLineResolver resolver;
  121. MinidumpProcessor processor(&supplier, &resolver, true);
  122. ProcessState state;
  123. string minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  124. "/src/processor/testdata/ascii_read_av.dmp";
  125. ASSERT_EQ(processor.Process(minidump_file, &state),
  126. google_breakpad::PROCESS_OK);
  127. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  128. state.exploitability());
  129. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  130. "/src/processor/testdata/ascii_read_av_block_write.dmp";
  131. ASSERT_EQ(processor.Process(minidump_file, &state),
  132. google_breakpad::PROCESS_OK);
  133. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  134. state.exploitability());
  135. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  136. "/src/processor/testdata/ascii_read_av_clobber_write.dmp";
  137. ASSERT_EQ(processor.Process(minidump_file, &state),
  138. google_breakpad::PROCESS_OK);
  139. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  140. state.exploitability());
  141. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  142. "/src/processor/testdata/ascii_read_av_conditional.dmp";
  143. ASSERT_EQ(processor.Process(minidump_file, &state),
  144. google_breakpad::PROCESS_OK);
  145. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  146. state.exploitability());
  147. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  148. "/src/processor/testdata/ascii_read_av_then_jmp.dmp";
  149. ASSERT_EQ(processor.Process(minidump_file, &state),
  150. google_breakpad::PROCESS_OK);
  151. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  152. state.exploitability());
  153. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  154. "/src/processor/testdata/ascii_read_av_xchg_write.dmp";
  155. ASSERT_EQ(processor.Process(minidump_file, &state),
  156. google_breakpad::PROCESS_OK);
  157. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  158. state.exploitability());
  159. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  160. "/src/processor/testdata/ascii_write_av.dmp";
  161. ASSERT_EQ(processor.Process(minidump_file, &state),
  162. google_breakpad::PROCESS_OK);
  163. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  164. state.exploitability());
  165. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  166. "/src/processor/testdata/ascii_write_av_arg_to_call.dmp";
  167. ASSERT_EQ(processor.Process(minidump_file, &state),
  168. google_breakpad::PROCESS_OK);
  169. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  170. state.exploitability());
  171. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  172. "/src/processor/testdata/null_read_av.dmp";
  173. ASSERT_EQ(processor.Process(minidump_file, &state),
  174. google_breakpad::PROCESS_OK);
  175. ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
  176. state.exploitability());
  177. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  178. "/src/processor/testdata/null_write_av.dmp";
  179. ASSERT_EQ(processor.Process(minidump_file, &state),
  180. google_breakpad::PROCESS_OK);
  181. ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
  182. state.exploitability());
  183. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  184. "/src/processor/testdata/stack_exhaustion.dmp";
  185. ASSERT_EQ(processor.Process(minidump_file, &state),
  186. google_breakpad::PROCESS_OK);
  187. ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
  188. state.exploitability());
  189. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  190. "/src/processor/testdata/exec_av_on_stack.dmp";
  191. ASSERT_EQ(processor.Process(minidump_file, &state),
  192. google_breakpad::PROCESS_OK);
  193. ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
  194. state.exploitability());
  195. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  196. "/src/processor/testdata/write_av_non_null.dmp";
  197. ASSERT_EQ(processor.Process(minidump_file, &state),
  198. google_breakpad::PROCESS_OK);
  199. ASSERT_EQ(google_breakpad::EXPLOITABLITY_MEDIUM,
  200. state.exploitability());
  201. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  202. "/src/processor/testdata/read_av_non_null.dmp";
  203. ASSERT_EQ(processor.Process(minidump_file, &state),
  204. google_breakpad::PROCESS_OK);
  205. ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
  206. state.exploitability());
  207. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  208. "/src/processor/testdata/read_av_clobber_write.dmp";
  209. ASSERT_EQ(processor.Process(minidump_file, &state),
  210. google_breakpad::PROCESS_OK);
  211. ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
  212. state.exploitability());
  213. minidump_file = string(getenv("srcdir") ? getenv("srcdir") : ".") +
  214. "/src/processor/testdata/read_av_conditional.dmp";
  215. ASSERT_EQ(processor.Process(minidump_file, &state),
  216. google_breakpad::PROCESS_OK);
  217. ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
  218. state.exploitability());
  219. }
  220. }