Module: wine Branch: master Commit: a76518c186ac0893ea460cd3b061096f1b05c8cc URL: https://source.winehq.org/git/wine.git/?a=commit;h=a76518c186ac0893ea460cd3b...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Dec 11 22:22:43 2019 +0100
kernelbase: Use exception handlers instead of IsBad* functions.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/kernelbase/memory.c | 15 ++++++++++++++- dlls/kernelbase/path.c | 25 ++++++++++++++++++------- dlls/kernelbase/registry.c | 11 ++++++++++- dlls/kernelbase/sync.c | 11 +++++++---- 4 files changed, 49 insertions(+), 13 deletions(-)
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c index 83805ece45..1bce74a636 100644 --- a/dlls/kernelbase/memory.c +++ b/dlls/kernelbase/memory.c @@ -688,7 +688,20 @@ LPVOID WINAPI DECLSPEC_HOTPATCH LocalLock( HLOCAL hmem ) { void *ret = NULL;
- if (is_pointer( hmem )) return IsBadReadPtr( hmem, 1 ) ? NULL : hmem; + if (is_pointer( hmem )) + { + __TRY + { + volatile char *p = hmem; + *p |= 0; + } + __EXCEPT_PAGE_FAULT + { + return NULL; + } + __ENDTRY + return hmem; + }
RtlLockHeap( GetProcessHeap() ); __TRY diff --git a/dlls/kernelbase/path.c b/dlls/kernelbase/path.c index 23476694db..9b016a882e 100644 --- a/dlls/kernelbase/path.c +++ b/dlls/kernelbase/path.c @@ -30,6 +30,7 @@ #include "winternl.h"
#include "kernelbase.h" +#include "wine/exception.h" #include "wine/debug.h" #include "wine/heap.h"
@@ -5049,10 +5050,15 @@ HRESULT WINAPI HashData(const unsigned char *src, DWORD src_len, unsigned char *
HRESULT WINAPI UrlHashA(const char *url, unsigned char *dest, DWORD dest_len) { - if (IsBadStringPtrA(url, -1) || IsBadWritePtr(dest, dest_len)) + __TRY + { + HashData((const BYTE *)url, (int)strlen(url), dest, dest_len); + } + __EXCEPT_PAGE_FAULT + { return E_INVALIDARG; - - HashData((const BYTE *)url, (int)strlen(url), dest, dest_len); + } + __ENDTRY return S_OK; }
@@ -5062,11 +5068,16 @@ HRESULT WINAPI UrlHashW(const WCHAR *url, unsigned char *dest, DWORD dest_len)
TRACE("%s, %p, %d\n", debugstr_w(url), dest, dest_len);
- if (IsBadStringPtrW(url, -1) || IsBadWritePtr(dest, dest_len)) + __TRY + { + WideCharToMultiByte(CP_ACP, 0, url, -1, urlA, MAX_PATH, NULL, NULL); + HashData((const BYTE *)urlA, (int)strlen(urlA), dest, dest_len); + } + __EXCEPT_PAGE_FAULT + { return E_INVALIDARG; - - WideCharToMultiByte(CP_ACP, 0, url, -1, urlA, MAX_PATH, NULL, NULL); - HashData((const BYTE *)urlA, (int)strlen(urlA), dest, dest_len); + } + __ENDTRY return S_OK; }
diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index 80f5ffef02..ad9a2a3366 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -41,6 +41,7 @@
#include "kernelbase.h" #include "wine/debug.h" +#include "wine/exception.h" #include "wine/heap.h" #include "wine/list.h"
@@ -3432,8 +3433,16 @@ LONG WINAPI SHRegWriteUSValueW(HUSKEY hUSKey, const WCHAR *value, DWORD type, vo
TRACE("%p, %s, %d, %p, %d, %#x\n", hUSKey, debugstr_w(value), type, data, data_len, flags);
- if (!hUSKey || IsBadWritePtr(hUSKey, sizeof(struct USKEY)) || !(flags & (SHREGSET_FORCE_HKCU|SHREGSET_FORCE_HKLM))) + __TRY + { + dummy = hKey->HKCUkey || hKey->HKLMkey; + } + __EXCEPT_PAGE_FAULT + { return ERROR_INVALID_PARAMETER; + } + __ENDTRY + if (!(flags & (SHREGSET_FORCE_HKCU|SHREGSET_FORCE_HKLM))) return ERROR_INVALID_PARAMETER;
if (flags & (SHREGSET_FORCE_HKCU | SHREGSET_HKCU)) { diff --git a/dlls/kernelbase/sync.c b/dlls/kernelbase/sync.c index 781a729ae9..b64c43dc05 100644 --- a/dlls/kernelbase/sync.c +++ b/dlls/kernelbase/sync.c @@ -36,6 +36,7 @@
#include "kernelbase.h" #include "wine/asm.h" +#include "wine/exception.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(sync); @@ -336,14 +337,16 @@ HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventExW( SECURITY_ATTRIBUTES *sa, LPCWSTR /* one buggy program needs this * ("Van Dale Groot woordenboek der Nederlandse taal") */ - if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES))) + __TRY + { + get_create_object_attributes( &attr, &nameW, sa, name ); + } + __EXCEPT_PAGE_FAULT { - ERR("Bad security attributes pointer %p\n",sa); SetLastError( ERROR_INVALID_PARAMETER); return 0; } - - get_create_object_attributes( &attr, &nameW, sa, name ); + __ENDTRY
status = NtCreateEvent( &ret, access, &attr, (flags & CREATE_EVENT_MANUAL_RESET) ? NotificationEvent : SynchronizationEvent,