From fd1c593ab6ba0d1cba81f9fed5ba931b23063ba5 Mon Sep 17 00:00:00 2001 From: gab Date: Thu, 14 Jan 2016 16:55:55 -0800 Subject: [PATCH] Cleanup API usage patterns in process_info_win.cc We're seeing crashes in ::GetProcessTimes() in issue 565905. While they appear to be in patched binaries we can potentially reduce their occurrence by at least not passing the same object in three out-params which aren't documented as being able to share the same object. BUG=565905 Review URL: https://codereview.chromium.org/1584213003 Cr-Commit-Position: refs/heads/master@{#369638} --- base/process/process_info_win.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/base/process/process_info_win.cc b/base/process/process_info_win.cc index ade45fd4b48f84..bd9e0702c3db30 100644 --- a/base/process/process_info_win.cc +++ b/base/process/process_info_win.cc @@ -16,11 +16,13 @@ namespace base { // static const Time CurrentProcessInfo::CreationTime() { FILETIME creation_time = {}; - FILETIME ignore = {}; - if (::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore, - &ignore, &ignore) == false) + FILETIME ignore1 = {}; + FILETIME ignore2 = {}; + FILETIME ignore3 = {}; + if (!::GetProcessTimes(::GetCurrentProcess(), &creation_time, &ignore1, + &ignore2, &ignore3)) { return Time(); - + } return Time::FromFileTime(creation_time); } @@ -36,7 +38,7 @@ IntegrityLevel GetCurrentProcessIntegrityLevel() { win::ScopedHandle scoped_process_token(process_token); DWORD token_info_length = 0; - if (::GetTokenInformation(process_token, TokenIntegrityLevel, NULL, 0, + if (::GetTokenInformation(process_token, TokenIntegrityLevel, nullptr, 0, &token_info_length) || ::GetLastError() != ERROR_INSUFFICIENT_BUFFER) { return INTEGRITY_UNKNOWN; @@ -58,7 +60,8 @@ IntegrityLevel GetCurrentProcessIntegrityLevel() { DWORD integrity_level = *::GetSidSubAuthority( token_label->Label.Sid, - static_cast(*::GetSidSubAuthorityCount(token_label->Label.Sid)-1)); + static_cast(*::GetSidSubAuthorityCount(token_label->Label.Sid) - + 1)); if (integrity_level < SECURITY_MANDATORY_MEDIUM_RID) return LOW_INTEGRITY;