diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 01:13:11 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-18 01:13:11 +0000 |
commit | 5c12226f43191ebc79168ff152f29ddea62bdfd5 (patch) | |
tree | 4d6d9981c6563ff317323f261c0a37300aa259f4 /base/iat_patch.cc | |
parent | ed64a95d47b66eaf73d6658dbfde812ab3c62689 (diff) | |
download | chromium_src-5c12226f43191ebc79168ff152f29ddea62bdfd5.zip chromium_src-5c12226f43191ebc79168ff152f29ddea62bdfd5.tar.gz chromium_src-5c12226f43191ebc79168ff152f29ddea62bdfd5.tar.bz2 |
Don't unpatch an unloaded module. We verify if the original function address is still valid
with a VirtualQuery call.
This fixes http://code.google.com/p/chromium/issues/detail?id=7701
Bug=7701
Review URL: http://codereview.chromium.org/21434
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/iat_patch.cc')
-rw-r--r-- | base/iat_patch.cc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/base/iat_patch.cc b/base/iat_patch.cc index 713aa92..2417608 100644 --- a/base/iat_patch.cc +++ b/base/iat_patch.cc @@ -205,9 +205,25 @@ DWORD IATPatchFunction::Patch(HMODULE module_handle, } DWORD IATPatchFunction::Unpatch() { - DWORD error = RestoreImportedFunction(intercept_function_, - original_function_, - iat_thunk_); + DWORD error = 0; + MEMORY_BASIC_INFORMATION memory_info = {0}; + + // If the module has already unloaded, no point trying to unpatch. + if (!VirtualQuery(original_function_, &memory_info, + sizeof(memory_info))) { + error = GetLastError(); + NOTREACHED(); + return error; + } + + if ((memory_info.State & MEM_COMMIT) != MEM_COMMIT) { + NOTREACHED(); + return ERROR_ACCESS_DENIED; + } + + error = RestoreImportedFunction(intercept_function_, + original_function_, + iat_thunk_); DCHECK(NO_ERROR == error); // Hands off the intercept if we fail to unpatch. |