From 382b72d729cdd3e5f61e924b9cfff2bab332b98e Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 10 Apr 2015 12:56:48 +0200 Subject: [PATCH] fusion: Support buffer size queries in IAssemblyName::GetName. --- dlls/fusion/asmname.c | 19 ++++++++++++------- dlls/fusion/tests/asmname.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/dlls/fusion/asmname.c b/dlls/fusion/asmname.c index f892f2bbc0d..c417a2391f8 100644 --- a/dlls/fusion/asmname.c +++ b/dlls/fusion/asmname.c @@ -369,19 +369,24 @@ static HRESULT WINAPI IAssemblyNameImpl_GetName(IAssemblyName *iface, WCHAR *pwzName) { IAssemblyNameImpl *name = impl_from_IAssemblyName(iface); + DWORD len; TRACE("(%p, %p, %p)\n", iface, lpcwBuffer, pwzName); - if (!name->name) + if (name->name) + len = strlenW(name->name) + 1; + else + len = 0; + + if (*lpcwBuffer < len) { - *pwzName = '\0'; - *lpcwBuffer = 0; - return S_OK; + *lpcwBuffer = len; + return E_NOT_SUFFICIENT_BUFFER; } + if (!name->name) lpcwBuffer[0] = 0; + else strcpyW(pwzName, name->name); - lstrcpyW(pwzName, name->name); - *lpcwBuffer = lstrlenW(pwzName) + 1; - + *lpcwBuffer = len; return S_OK; } diff --git a/dlls/fusion/tests/asmname.c b/dlls/fusion/tests/asmname.c index a0752881331..68309f2980f 100644 --- a/dlls/fusion/tests/asmname.c +++ b/dlls/fusion/tests/asmname.c @@ -421,12 +421,12 @@ static void test_CreateAssemblyNameObject(void) broken(hr == E_INVALIDARG), /* .NET 1.x */ "Expected FUSION_E_INVALID_NAME, got %08x\n", hr); + str[0] = 'a'; size = MAX_PATH; - str[0] = '\0'; hr = IAssemblyName_GetName(name, &size, str); - ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); - ok(!str[0], "Expected empty name\n"); - ok(size == 0, "Expected 0, got %d\n", size); + ok(hr == S_OK, "got %08x\n", hr); + ok(str[0] == 'a', "got %c\n", str[0]); + ok(!size, "got %u\n", size); hi = 0xbeefcace; lo = 0xcafebabe; @@ -457,6 +457,26 @@ static void test_CreateAssemblyNameObject(void) broken(hr == S_OK), /* .NET 1.x */ "Expected FUSION_E_INVALID_NAME, got %08x\n", hr); + size = 0; + hr = IAssemblyName_GetName(name, &size, NULL); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr); + ok(size == 1, "got %u\n", size); + + if (0) /* crash */ + { + str[0] = '\0'; + hr = IAssemblyName_GetName(name, NULL, str); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr); + ok(!str[0], "got %c\n", str[0]); + } + + size = 0; + str[0] = '\0'; + hr = IAssemblyName_GetName(name, &size, str); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr); + ok(!str[0], "got %c\n", str[0]); + ok(size == 1, "got %u\n", size); + size = MAX_PATH; str[0] = '\0'; hr = IAssemblyName_GetName(name, &size, str); @@ -494,6 +514,13 @@ static void test_CreateAssemblyNameObject(void) ok_aw("wine", str); ok(size == 5, "Expected 5, got %d\n", size); + size = 0; + str[0] = 0; + hr = IAssemblyName_GetName(name, &size, str); + ok(hr == E_NOT_SUFFICIENT_BUFFER, "got %08x\n", hr); + ok(!str[0], "got %c\n", str[0]); + ok(size == 5, "got %u\n", size); + size = MAX_PATH; str[0] = '\0'; hr = IAssemblyName_GetName(name, &size, str);