fusion: Fix insufficient buffer size handling in IAssemblyName::GetDisplayName.

This commit is contained in:
Hans Leidekker 2015-04-10 12:57:15 +02:00 committed by Alexandre Julliard
parent 382b72d729
commit 2eda884bd7
2 changed files with 28 additions and 7 deletions

View File

@ -228,12 +228,10 @@ static HRESULT WINAPI IAssemblyNameImpl_GetDisplayName(IAssemblyName *iface,
LPDWORD pccDisplayName,
DWORD dwDisplayFlags)
{
IAssemblyNameImpl *name = impl_from_IAssemblyName(iface);
WCHAR verstr[30];
DWORD size;
LPWSTR cultureval = 0;
static const WCHAR equals[] = {'=',0};
IAssemblyNameImpl *name = impl_from_IAssemblyName(iface);
WCHAR verstr[30], *cultureval = NULL;
DWORD size;
TRACE("(%p, %p, %p, %d)\n", iface, szDisplayName,
pccDisplayName, dwDisplayFlags);
@ -243,9 +241,15 @@ static HRESULT WINAPI IAssemblyNameImpl_GetDisplayName(IAssemblyName *iface,
if (!name->displayname || !*name->displayname)
return FUSION_E_INVALID_NAME;
size = min(*pccDisplayName, lstrlenW(name->displayname) + 1);
size = strlenW(name->displayname) + 1;
lstrcpynW(szDisplayName, name->displayname, size);
if (*pccDisplayName < size)
{
*pccDisplayName = size;
return E_NOT_SUFFICIENT_BUFFER;
}
if (szDisplayName) strcpyW(szDisplayName, name->displayname);
*pccDisplayName = size;
return S_OK;

View File

@ -508,6 +508,23 @@ static void test_CreateAssemblyNameObject(void)
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
ok(name != NULL, "Expected non-NULL name\n");
size = 0;
hr = IAssemblyName_GetDisplayName(name, NULL, &size, 0);
ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr);
ok(size == 5, "got %u\n", size);
size = 3;
hr = IAssemblyName_GetDisplayName(name, NULL, &size, 0);
ok(hr == E_NOT_SUFFICIENT_BUFFER || broken(hr == E_INVALIDARG), "got %08x\n", hr);
ok(size == 5 || broken(size == 3), "got %u\n", size);
size = 3;
str[0] = 'a';
hr = IAssemblyName_GetDisplayName(name, str, &size, 0);
ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr);
ok(str[0] == 'a', "got %c\n", str[0]);
ok(size == 5, "got %u\n", size);
size = MAX_PATH;
hr = IAssemblyName_GetDisplayName(name, str, &size, ASM_DISPLAYF_FULL);
ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);