From 27add94454c6b70921fb0718b5dbbd77eae3c5ec Mon Sep 17 00:00:00 2001 From: finnur Date: Mon, 21 Dec 2015 02:21:33 -0800 Subject: Revert of Allow IAT patches to fail when patching for Active Verifier. (patchset #3 id:40001 of https://codereview.chromium.org/1540723002/ ) Reason for revert: Seems to consistently cause Win7 tests to fail. Example log: https://build.chromium.org/p/chromium.win/builders/Win7%20Tests%20%28dbg%29%281%29/builds/44171/steps/base_unittests/logs/stdio Original issue's description: > Allow IAT patches to fail when patching for Active Verifier. > > Not all loaded modules import CloseHandle and DuplicateHandle so > InstallHandleHooks was failing incorrectly and causing the Handle > Verifier to be disabled. > > Also, continue to patch DuplicateHandle if a module happens to > not import CloseHandle. > > BUG=570912 > > Committed: https://crrev.com/c844be97c13fcf492149a21a0f3d9bf083c3c0d2 > Cr-Commit-Position: refs/heads/master@{#366322} TBR=cpu@chromium.org,wfh@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=570912 Review URL: https://codereview.chromium.org/1542553002 Cr-Commit-Position: refs/heads/master@{#366362} --- base/debug/close_handle_hook_win.cc | 20 ++++++++++++-------- base/test/run_all_unittests.cc | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/base/debug/close_handle_hook_win.cc b/base/debug/close_handle_hook_win.cc index 70d40b2..359b758 100644 --- a/base/debug/close_handle_hook_win.cc +++ b/base/debug/close_handle_hook_win.cc @@ -203,14 +203,15 @@ bool HandleHooks::AddIATPatch(HMODULE module) { base::win::IATPatchFunction* patch = NULL; patch = IATPatch(module, "CloseHandle", &CloseHandleHook, reinterpret_cast(&g_close_function)); - if (patch) - hooks_.push_back(patch); + if (!patch) + return false; + hooks_.push_back(patch); patch = IATPatch(module, "DuplicateHandle", &DuplicateHandleHook, reinterpret_cast(&g_duplicate_function)); - if (patch) - hooks_.push_back(patch); - + if (!patch) + return false; + hooks_.push_back(patch); return true; } @@ -248,12 +249,15 @@ bool PatchLoadedModules(HandleHooks* hooks) { returned /= sizeof(HMODULE); returned = std::min(kSize, returned); + bool success = false; + for (DWORD current = 0; current < returned; current++) { - if (!hooks->AddIATPatch(modules[current])) - return false; + success = hooks->AddIATPatch(modules[current]); + if (!success) + break; } - return true; + return success; } } // namespace diff --git a/base/test/run_all_unittests.cc b/base/test/run_all_unittests.cc index f3fb3d1..84e6d3f 100644 --- a/base/test/run_all_unittests.cc +++ b/base/test/run_all_unittests.cc @@ -22,7 +22,7 @@ int main(int argc, char** argv) { #endif base::TestSuite test_suite(argc, argv); #if defined(OS_WIN) - CHECK(base::debug::InstallHandleHooks()); + base::debug::InstallHandleHooks(); #endif int ret = base::LaunchUnitTests( argc, argv, -- cgit v1.1