wintrust: Don't fail CryptCATOpen on empty file or invalid data.

Fixes a regression from 699e0a55ea,
making "winetricks dotnet30sp1" fail.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49831
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2020-12-16 22:17:16 +01:00 committed by Alexandre Julliard
parent afac4f09c7
commit 0fb7ea9120
2 changed files with 18 additions and 8 deletions

View File

@ -908,6 +908,7 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
BYTE *buffer = NULL;
DWORD size, open_mode = OPEN_ALWAYS;
struct cryptcat *cc;
BOOL valid;
TRACE("filename %s, flags %#x, provider %#lx, version %#x, type %#x\n",
debugstr_w(filename), flags, hProv, dwPublicVersion, dwEncodingType);
@ -941,13 +942,15 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
HeapFree(GetProcessHeap(), 0, buffer);
return INVALID_HANDLE_VALUE;
}
if (!ReadFile(file, buffer, size, &size, NULL) || !CryptMsgUpdate(hmsg, buffer, size, TRUE))
if (!size) valid = FALSE;
else if (!ReadFile(file, buffer, size, &size, NULL))
{
CloseHandle(file);
HeapFree(GetProcessHeap(), 0, buffer);
CryptMsgClose(hmsg);
return INVALID_HANDLE_VALUE;
}
else valid = CryptMsgUpdate(hmsg, buffer, size, TRUE);
HeapFree(GetProcessHeap(), 0, buffer);
CloseHandle(file);
@ -961,7 +964,13 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
cc->msg = hmsg;
cc->encoding = dwEncodingType;
if (CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_COUNT_PARAM, 0, &cc->attr_count, &size))
if (!valid)
{
cc->magic = CRYPTCAT_MAGIC;
SetLastError(ERROR_SUCCESS);
return cc;
}
else if (CryptMsgGetParam(hmsg, CMSG_ATTR_CERT_COUNT_PARAM, 0, &cc->attr_count, &size))
{
DWORD i, sum = 0;
BYTE *p;
@ -1012,6 +1021,7 @@ HANDLE WINAPI CryptCATOpen(WCHAR *filename, DWORD flags, HCRYPTPROV hProv,
return INVALID_HANDLE_VALUE;
}
cc->magic = CRYPTCAT_MAGIC;
SetLastError(ERROR_SUCCESS);
return cc;
}
HeapFree(GetProcessHeap(), 0, cc);

View File

@ -429,10 +429,10 @@ static void test_CryptCATOpen(void)
}
else
{
todo_wine ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
todo_wine ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ret = pCryptCATClose(cat);
todo_wine ok(ret, "flags %#x: failed to close file\n", flags);
ok(ret, "flags %#x: failed to close file\n", flags);
ret = DeleteFileW(filename);
ok(ret, "flags %#x: failed to delete file, error %u\n", flags, GetLastError());
}
@ -443,10 +443,10 @@ static void test_CryptCATOpen(void)
SetLastError(0xdeadbeef);
cat = pCryptCATOpen(filename, flags, 0, 0, 0);
todo_wine ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
todo_wine ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ok(cat != INVALID_HANDLE_VALUE, "flags %#x: expected success\n", flags);
ok(!GetLastError(), "flags %#x: got error %u\n", flags, GetLastError());
ret = pCryptCATClose(cat);
todo_wine ok(ret, "flags %#x: failed to close file\n", flags);
ok(ret, "flags %#x: failed to close file\n", flags);
file = _wfopen(filename, L"r");
ret = fread(buffer, 1, sizeof(buffer), file);