From 3a886267aaf055db86030723cb568acb88915190 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Fri, 11 Sep 2015 13:16:06 -0700 Subject: [PATCH] win: Fix OpenProcess(PROCESS_ALL_ACCESS, ...) on XP PROCESS_ALL_ACCESS was changed in later SDKs and the newer value fails when run on XP with ERROR_ACCESS_DENIED. Use the old value to maintain compatibility with XP. R=mark@chromium.org BUG=crashpad:50 Review URL: https://codereview.chromium.org/1337133002 . --- tools/generate_dump.cc | 3 ++- util/util.gyp | 1 + util/win/exception_handler_server.cc | 5 +++-- util/win/xp_compat.h | 33 ++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 util/win/xp_compat.h diff --git a/tools/generate_dump.cc b/tools/generate_dump.cc index c68d214a..e3679749 100644 --- a/tools/generate_dump.cc +++ b/tools/generate_dump.cc @@ -42,6 +42,7 @@ #include "base/strings/utf_string_conversions.h" #include "snapshot/win/process_snapshot_win.h" #include "util/win/scoped_process_suspend.h" +#include "util/win/xp_compat.h" #endif // OS_MACOSX namespace crashpad { @@ -151,7 +152,7 @@ int GenerateDumpMain(int argc, char* argv[]) { } #elif defined(OS_WIN) ScopedKernelHANDLE process( - OpenProcess(PROCESS_ALL_ACCESS, false, options.pid)); + OpenProcess(kXPProcessAllAccess, false, options.pid)); if (!process.is_valid()) { LOG(ERROR) << "could not open process " << options.pid; return EXIT_FAILURE; diff --git a/util/util.gyp b/util/util.gyp index 95a263c9..1e06efb2 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -166,6 +166,7 @@ 'win/scoped_process_suspend.h', 'win/time.cc', 'win/time.h', + 'win/xp_compat.h', ], 'conditions': [ ['OS=="mac"', { diff --git a/util/win/exception_handler_server.cc b/util/win/exception_handler_server.cc index 547087e0..2d702f20 100644 --- a/util/win/exception_handler_server.cc +++ b/util/win/exception_handler_server.cc @@ -27,6 +27,7 @@ #include "util/misc/tri_state.h" #include "util/misc/uuid.h" #include "util/win/registration_protocol_win.h" +#include "util/win/xp_compat.h" namespace crashpad { @@ -342,14 +343,14 @@ bool ExceptionHandlerServer::ServiceClientConnection( // the process, but the client will be able to, so we make a second attempt // having impersonated the client. HANDLE client_process = OpenProcess( - PROCESS_ALL_ACCESS, false, message.registration.client_process_id); + kXPProcessAllAccess, false, message.registration.client_process_id); if (!client_process) { if (!ImpersonateNamedPipeClient(service_context.pipe())) { PLOG(ERROR) << "ImpersonateNamedPipeClient"; return false; } HANDLE client_process = OpenProcess( - PROCESS_ALL_ACCESS, false, message.registration.client_process_id); + kXPProcessAllAccess, false, message.registration.client_process_id); PCHECK(RevertToSelf()); if (!client_process) { LOG(ERROR) << "failed to open " << message.registration.client_process_id; diff --git a/util/win/xp_compat.h b/util/win/xp_compat.h new file mode 100644 index 00000000..1501f3c5 --- /dev/null +++ b/util/win/xp_compat.h @@ -0,0 +1,33 @@ +// 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. + +#ifndef CRASHPAD_UTIL_WIN_XP_COMPAT_H_ +#define CRASHPAD_UTIL_WIN_XP_COMPAT_H_ + +#include + +namespace crashpad { + +enum { + //! \brief This is the XP-suitable value of `PROCESS_ALL_ACCESS`. + //! + //! Requesting `PROCESS_ALL_ACCESS` with the value defined when building + //! against a Vista+ SDK results in `ERROR_ACCESS_DENIED` when running on XP. + //! See https://msdn.microsoft.com/en-ca/library/windows/desktop/ms684880.aspx + kXPProcessAllAccess = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF +}; + +} // namespace crashpad + +#endif // CRASHPAD_UTIL_WIN_XP_COMPAT_H_