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

Side by Side Diff: sandbox/win/src/address_sanitizer_test.cc

Issue 1849323003: Convert //sandbox to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
Will Harris 2016/04/04 21:05:57 memory.h
Mostyn Bramley-Moore 2016/04/05 07:11:00 Done.
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/win/scoped_handle.h" 12 #include "base/win/scoped_handle.h"
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #include "sandbox/win/tests/common/controller.h" 14 #include "sandbox/win/tests/common/controller.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace sandbox { 17 namespace sandbox {
18 18
19 class AddressSanitizerTests : public ::testing::Test { 19 class AddressSanitizerTests : public ::testing::Test {
20 public: 20 public:
21 void SetUp() override { 21 void SetUp() override {
22 env_.reset(base::Environment::Create()); 22 env_.reset(base::Environment::Create());
23 had_asan_options_ = env_->GetVar("ASAN_OPTIONS", &old_asan_options_); 23 had_asan_options_ = env_->GetVar("ASAN_OPTIONS", &old_asan_options_);
24 } 24 }
25 25
26 void TearDown() override { 26 void TearDown() override {
27 if (had_asan_options_) 27 if (had_asan_options_)
28 ASSERT_TRUE(env_->SetVar("ASAN_OPTIONS", old_asan_options_)); 28 ASSERT_TRUE(env_->SetVar("ASAN_OPTIONS", old_asan_options_));
29 else 29 else
30 env_->UnSetVar("ASAN_OPTIONS"); 30 env_->UnSetVar("ASAN_OPTIONS");
31 } 31 }
32 32
33 protected: 33 protected:
34 scoped_ptr<base::Environment> env_; 34 std::unique_ptr<base::Environment> env_;
35 bool had_asan_options_; 35 bool had_asan_options_;
36 std::string old_asan_options_; 36 std::string old_asan_options_;
37 }; 37 };
38 38
39 SBOX_TESTS_COMMAND int AddressSanitizerTests_Report(int argc, wchar_t** argv) { 39 SBOX_TESTS_COMMAND int AddressSanitizerTests_Report(int argc, wchar_t** argv) {
40 // AddressSanitizer should detect an out of bounds write (heap buffer 40 // AddressSanitizer should detect an out of bounds write (heap buffer
41 // overflow) in this code. 41 // overflow) in this code.
42 volatile int idx = 42; 42 volatile int idx = 42;
43 int *volatile blah = new int[42]; 43 int *volatile blah = new int[42];
44 blah[idx] = 42; 44 blah[idx] = 42;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 size_t last_slash = source_file_basename.find_last_of("/\\"); 97 size_t last_slash = source_file_basename.find_last_of("/\\");
98 last_slash = last_slash == std::string::npos ? 0 : last_slash + 1; 98 last_slash = last_slash == std::string::npos ? 0 : last_slash + 1;
99 ASSERT_TRUE(strstr(data.c_str(), &source_file_basename[last_slash])) 99 ASSERT_TRUE(strstr(data.c_str(), &source_file_basename[last_slash]))
100 << "The stack trace doesn't have a correct filename:\n" << data; 100 << "The stack trace doesn't have a correct filename:\n" << data;
101 } else { 101 } else {
102 LOG(WARNING) << "Not an AddressSanitizer build, skipping the run."; 102 LOG(WARNING) << "Not an AddressSanitizer build, skipping the run.";
103 } 103 }
104 } 104 }
105 105
106 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698