Commit 0fb7ea91 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

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

Fixes a regression from 699e0a55, making "winetricks dotnet30sp1" fail. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49831Signed-off-by: 's avatarRémi Bernon <rbernon@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent afac4f09
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment