1// Copyright (c) 2010, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14//     * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
29
30#include <stdlib.h>
31#include <unistd.h>
32
33#include <string>
34
35#include "breakpad_googletest_includes.h"
36#include "common/using_std_string.h"
37#include "google_breakpad/processor/basic_source_line_resolver.h"
38#include "google_breakpad/processor/minidump_processor.h"
39#include "google_breakpad/processor/process_state.h"
40#include "processor/simple_symbol_supplier.h"
41
42namespace {
43
44using google_breakpad::BasicSourceLineResolver;
45using google_breakpad::MinidumpProcessor;
46using google_breakpad::ProcessState;
47using google_breakpad::SimpleSymbolSupplier;
48
49string TestDataDir() {
50  return string(getenv("srcdir") ? getenv("srcdir") : ".") +
51      "/src/processor/testdata";
52}
53
54// Find the given dump file in <srcdir>/src/processor/testdata, process it,
55// and get the exploitability rating. Returns EXPLOITABILITY_ERR_PROCESSING
56// if the crash dump can't be processed.
57google_breakpad::ExploitabilityRating
58ExploitabilityFor(const string& filename) {
59  SimpleSymbolSupplier supplier(TestDataDir() + "/symbols");
60  BasicSourceLineResolver resolver;
61  MinidumpProcessor processor(&supplier, &resolver, true);
62  ProcessState state;
63
64  string minidump_file = TestDataDir() + "/" + filename;
65
66  if (processor.Process(minidump_file, &state) !=
67      google_breakpad::PROCESS_OK) {
68    return google_breakpad::EXPLOITABILITY_ERR_PROCESSING;
69  }
70
71  return state.exploitability();
72}
73
74TEST(ExploitabilityTest, TestWindowsEngine) {
75  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
76            ExploitabilityFor("ascii_read_av.dmp"));
77  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
78            ExploitabilityFor("ascii_read_av_block_write.dmp"));
79  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
80            ExploitabilityFor("ascii_read_av_clobber_write.dmp"));
81  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
82            ExploitabilityFor("ascii_read_av_conditional.dmp"));
83  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
84            ExploitabilityFor("ascii_read_av_then_jmp.dmp"));
85  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
86            ExploitabilityFor("ascii_read_av_xchg_write.dmp"));
87  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
88            ExploitabilityFor("ascii_write_av.dmp"));
89  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
90            ExploitabilityFor("ascii_write_av_arg_to_call.dmp"));
91  ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
92            ExploitabilityFor("null_read_av.dmp"));
93  ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
94            ExploitabilityFor("null_write_av.dmp"));
95  ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
96            ExploitabilityFor("stack_exhaustion.dmp"));
97  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
98            ExploitabilityFor("exec_av_on_stack.dmp"));
99  ASSERT_EQ(google_breakpad::EXPLOITABILITY_MEDIUM,
100            ExploitabilityFor("write_av_non_null.dmp"));
101  ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
102            ExploitabilityFor("read_av_non_null.dmp"));
103  ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
104            ExploitabilityFor("read_av_clobber_write.dmp"));
105  ASSERT_EQ(google_breakpad::EXPLOITABILITY_LOW,
106            ExploitabilityFor("read_av_conditional.dmp"));
107}
108
109TEST(ExploitabilityTest, TestLinuxEngine) {
110  ASSERT_EQ(google_breakpad::EXPLOITABILITY_NONE,
111            ExploitabilityFor("linux_null_read_av.dmp"));
112  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
113            ExploitabilityFor("linux_overflow.dmp"));
114  ASSERT_EQ(google_breakpad::EXPLOITABILITY_HIGH,
115            ExploitabilityFor("linux_stacksmash.dmp"));
116}
117}
118