mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
win: Don't duplicate handles in handle restriction list
R=mark@chromium.org BUG=crashpad:77 Review URL: https://codereview.chromium.org/1464473003 .
This commit is contained in:
parent
4f09b58d1f
commit
3562fe4ccd
@ -22,6 +22,7 @@
|
||||
'type': 'executable',
|
||||
'dependencies': [
|
||||
'client.gyp:crashpad_client',
|
||||
'../handler/handler.gyp:crashpad_handler',
|
||||
'../test/test.gyp:crashpad_test',
|
||||
'../third_party/gtest/gmock.gyp:gmock',
|
||||
'../third_party/gtest/gmock.gyp:gmock_main',
|
||||
@ -35,6 +36,7 @@
|
||||
'sources': [
|
||||
'capture_context_mac_test.cc',
|
||||
'crash_report_database_test.cc',
|
||||
'crashpad_client_win_test.cc',
|
||||
'prune_crash_reports_test.cc',
|
||||
'settings_test.cc',
|
||||
'simple_string_dictionary_test.cc',
|
||||
|
@ -132,7 +132,8 @@ using ScopedProcThreadAttributeList =
|
||||
base::ScopedGeneric<PPROC_THREAD_ATTRIBUTE_LIST,
|
||||
ScopedProcThreadAttributeListTraits>;
|
||||
|
||||
// Adds |handle| to |handle_list| if it appears valid.
|
||||
// Adds |handle| to |handle_list| if it appears valid, and is not already in
|
||||
// |handle_list|.
|
||||
//
|
||||
// Invalid handles (including INVALID_HANDLE_VALUE and null handles) cannot be
|
||||
// added to a PPROC_THREAD_ATTRIBUTE_LIST’s PROC_THREAD_ATTRIBUTE_HANDLE_LIST.
|
||||
@ -142,7 +143,12 @@ using ScopedProcThreadAttributeList =
|
||||
//
|
||||
// Use this function to add handles with uncertain validities.
|
||||
void AddHandleToListIfValid(std::vector<HANDLE>* handle_list, HANDLE handle) {
|
||||
if (handle && handle != INVALID_HANDLE_VALUE) {
|
||||
// There doesn't seem to be any documentation of this, but if there's a handle
|
||||
// duplicated in this list, CreateProcess() fails with
|
||||
// ERROR_INVALID_PARAMETER.
|
||||
if (handle && handle != INVALID_HANDLE_VALUE &&
|
||||
std::find(handle_list->begin(), handle_list->end(), handle) ==
|
||||
handle_list->end()) {
|
||||
handle_list->push_back(handle);
|
||||
}
|
||||
}
|
||||
@ -337,6 +343,7 @@ bool CrashpadClient::UseHandler() {
|
||||
DCHECK_EQ(g_signal_non_crash_dump, INVALID_HANDLE_VALUE);
|
||||
DCHECK_EQ(g_non_crash_dump_done, INVALID_HANDLE_VALUE);
|
||||
DCHECK(!g_critical_section_with_debug_info.DebugInfo);
|
||||
DCHECK(!g_non_crash_dump_lock);
|
||||
|
||||
ClientToServerMessage message;
|
||||
memset(&message, 0, sizeof(message));
|
||||
|
91
client/crashpad_client_win_test.cc
Normal file
91
client/crashpad_client_win_test.cc
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright 2015 The Crashpad Authors. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "client/crashpad_client.h"
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "test/paths.h"
|
||||
#include "test/scoped_temp_dir.h"
|
||||
#include "test/win/win_multiprocess.h"
|
||||
|
||||
namespace crashpad {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
void StartAndUseHandler() {
|
||||
ScopedTempDir temp_dir;
|
||||
base::FilePath handler_path = Paths::Executable().DirName().Append(
|
||||
FILE_PATH_LITERAL("crashpad_handler.exe"));
|
||||
CrashpadClient client;
|
||||
ASSERT_TRUE(client.StartHandler(handler_path,
|
||||
temp_dir.path(),
|
||||
"",
|
||||
std::map<std::string, std::string>(),
|
||||
std::vector<std::string>(),
|
||||
false));
|
||||
EXPECT_TRUE(client.UseHandler());
|
||||
}
|
||||
|
||||
class StartWithInvalidHandles final : public WinMultiprocess {
|
||||
public:
|
||||
StartWithInvalidHandles() : WinMultiprocess() {}
|
||||
~StartWithInvalidHandles() {}
|
||||
|
||||
private:
|
||||
void WinMultiprocessParent() override {}
|
||||
|
||||
void WinMultiprocessChild() override {
|
||||
HANDLE original_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
HANDLE original_stderr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
|
||||
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
||||
|
||||
StartAndUseHandler();
|
||||
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
|
||||
SetStdHandle(STD_ERROR_HANDLE, original_stderr);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(CrashpadClient, StartWithInvalidHandles) {
|
||||
WinMultiprocess::Run<StartWithInvalidHandles>();
|
||||
}
|
||||
|
||||
class StartWithSameStdoutStderr final : public WinMultiprocess {
|
||||
public:
|
||||
StartWithSameStdoutStderr() : WinMultiprocess() {}
|
||||
~StartWithSameStdoutStderr() {}
|
||||
|
||||
private:
|
||||
void WinMultiprocessParent() override {}
|
||||
|
||||
void WinMultiprocessChild() override {
|
||||
HANDLE original_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
HANDLE original_stderr = GetStdHandle(STD_ERROR_HANDLE);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, original_stderr);
|
||||
|
||||
StartAndUseHandler();
|
||||
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, original_stdout);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(CrashpadClient, StartWithSameStdoutStderr) {
|
||||
WinMultiprocess::Run<StartWithSameStdoutStderr>();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace test
|
||||
} // namespace crashpad
|
Loading…
x
Reference in New Issue
Block a user