Fixes crash on start in "Re:ZERO -Starting Life in Another World- The Prophecy of the Throne".
Signed-off-by: Paul Gofman pgofman@codeweavers.com --- dlls/advapi32/crypt.c | 15 +++++++++++++-- dlls/advapi32/tests/crypt.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index 91da4034405..52ccc4f09cc 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -37,6 +37,7 @@ #include "winreg.h" #include "rpc.h" #include "wine/debug.h" +#include "wine/exception.h" #include "winternl.h"
WINE_DEFAULT_DEBUG_CHANNEL(crypt); @@ -64,11 +65,21 @@ static void *pointer_from_handle(UINT_PTR handle, DWORD magic, DWORD invalid_han SetLastError(invalid_handle_error_code); return NULL; } - if (*(DWORD *)handle != magic) + + __TRY { - SetLastError(ERROR_INVALID_PARAMETER); + if (*(DWORD *)handle != magic) + { + SetLastError(ERROR_INVALID_PARAMETER); + return NULL; + } + } + __EXCEPT_PAGE_FAULT + { + SetLastError(invalid_handle_error_code); return NULL; } + __ENDTRY
return (void *)handle; } diff --git a/dlls/advapi32/tests/crypt.c b/dlls/advapi32/tests/crypt.c index 8d4f2ae5936..d9d6a97c681 100644 --- a/dlls/advapi32/tests/crypt.c +++ b/dlls/advapi32/tests/crypt.c @@ -154,6 +154,8 @@ static void test_CryptReleaseContext(void)
ret = CryptContextAddRef(0, NULL, 0); ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %u\n", GetLastError()); + ret = CryptContextAddRef(0xdeadbeef, NULL, 0); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %u\n", GetLastError());
ret = CryptReleaseContext(prov, 0); ok(ret, "got %u\n", GetLastError()); @@ -272,11 +274,17 @@ static void test_incorrect_api_usage(void) ok (result, "%08x\n", GetLastError()); if (!result) return;
+ /* Looks like native handles are just pointers. */ + ok(!!*(void **)hProv, "Got zero *(void **)hProv.\n"); + result = CryptCreateHash(hProv, CALG_SHA, 0, 0, &hHash); ok (result, "%d\n", GetLastError()); if (!result) return; CryptDestroyHash(hHash);
+ result = CryptCreateHash(0xdeadbeef, CALG_SHA, 0, 0, &hHash); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptCreateHash(0, CALG_SHA, 0, 0, &hHash); ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError());
@@ -287,6 +295,29 @@ static void test_incorrect_api_usage(void) ok (result, "%d\n", GetLastError()); if (!result) return;
+ dwLen = 1; + result = CryptDecrypt(hKey, 0, TRUE, 0, &temp, &dwLen); + ok (result, "%d\n", GetLastError()); + result = CryptDecrypt(hKey, 0xdeadbeef, TRUE, 0, &temp, &dwLen); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptDecrypt(0, 0, TRUE, 0, &temp, &dwLen); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptDecrypt(0xdeadbeef, 0, TRUE, 0, &temp, &dwLen); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + + result = CryptEncrypt(hKey, 0, TRUE, 0, &temp, &dwLen, sizeof(temp)); + ok (result, "%d\n", GetLastError()); + result = CryptEncrypt(hKey, 0xdeadbeef, TRUE, 0, &temp, &dwLen, sizeof(temp)); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptEncrypt(0, 0, TRUE, 0, &temp, &dwLen, sizeof(temp)); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptEncrypt(0xdeadbeef, 0, TRUE, 0, &temp, &dwLen, sizeof(temp)); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + + dwLen = 1; + result = CryptExportKey(hKey, 0xdeadbeef, 0, 0, &temp, &dwLen); + ok (!result && GetLastError() == ERROR_INVALID_PARAMETER, "%d\n", GetLastError()); + result = CryptDestroyKey(hKey); ok (result, "%d\n", GetLastError());