forked from Mirrors/wine-wine
advapi32: Fix GetServiceDisplayNameA for cchBuffer == 0.
parent
8fd1cf0f56
commit
a8b8ddd865
|
@ -2231,49 +2231,40 @@ BOOL WINAPI QueryServiceLockStatusW( SC_HANDLE hSCManager,
|
||||||
BOOL WINAPI GetServiceDisplayNameA( SC_HANDLE hSCManager, LPCSTR lpServiceName,
|
BOOL WINAPI GetServiceDisplayNameA( SC_HANDLE hSCManager, LPCSTR lpServiceName,
|
||||||
LPSTR lpDisplayName, LPDWORD lpcchBuffer)
|
LPSTR lpDisplayName, LPDWORD lpcchBuffer)
|
||||||
{
|
{
|
||||||
LPWSTR lpServiceNameW, lpDisplayNameW = NULL;
|
LPWSTR lpServiceNameW, lpDisplayNameW;
|
||||||
DWORD size, sizeW, GLE;
|
DWORD sizeW;
|
||||||
BOOL ret;
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
TRACE("%p %s %p %p\n", hSCManager,
|
TRACE("%p %s %p %p\n", hSCManager,
|
||||||
debugstr_a(lpServiceName), lpDisplayName, lpcchBuffer);
|
debugstr_a(lpServiceName), lpDisplayName, lpcchBuffer);
|
||||||
|
|
||||||
lpServiceNameW = SERV_dup(lpServiceName);
|
lpServiceNameW = SERV_dup(lpServiceName);
|
||||||
lpDisplayNameW = HeapAlloc(GetProcessHeap(), 0, *lpcchBuffer * sizeof(WCHAR));
|
if (lpDisplayName)
|
||||||
|
lpDisplayNameW = HeapAlloc(GetProcessHeap(), 0, *lpcchBuffer * sizeof(WCHAR));
|
||||||
|
else
|
||||||
|
lpDisplayNameW = NULL;
|
||||||
|
|
||||||
size = sizeW = *lpcchBuffer;
|
sizeW = *lpcchBuffer;
|
||||||
ret = GetServiceDisplayNameW(hSCManager, lpServiceNameW,
|
if (!GetServiceDisplayNameW(hSCManager, lpServiceNameW, lpDisplayNameW, &sizeW))
|
||||||
lpDisplayName ? lpDisplayNameW : NULL,
|
|
||||||
&sizeW);
|
|
||||||
/* Last error will be set by GetServiceDisplayNameW and must be preserved */
|
|
||||||
GLE = GetLastError();
|
|
||||||
|
|
||||||
if (!lpDisplayName && *lpcchBuffer && !ret && (GLE == ERROR_INSUFFICIENT_BUFFER))
|
|
||||||
{
|
{
|
||||||
/* Request for buffersize.
|
*lpcchBuffer = sizeW*2; /* we can only provide an upper estimation of string length */
|
||||||
*
|
goto cleanup;
|
||||||
* Only set the size for ERROR_INSUFFICIENT_BUFFER
|
|
||||||
*/
|
|
||||||
size = sizeW * 2;
|
|
||||||
}
|
|
||||||
else if (lpDisplayName && *lpcchBuffer && !ret)
|
|
||||||
{
|
|
||||||
/* Request for displayname.
|
|
||||||
*
|
|
||||||
* size only has to be set if this fails
|
|
||||||
*/
|
|
||||||
size = sizeW * 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WideCharToMultiByte(CP_ACP, 0, lpDisplayNameW, (sizeW + 1), lpDisplayName,
|
if (!WideCharToMultiByte(CP_ACP, 0, lpDisplayNameW, (sizeW + 1), lpDisplayName,
|
||||||
*lpcchBuffer, NULL, NULL );
|
*lpcchBuffer, NULL, NULL ))
|
||||||
|
{
|
||||||
|
*lpcchBuffer = WideCharToMultiByte(CP_ACP, 0, lpDisplayNameW, -1, NULL, 0, NULL, NULL);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
*lpcchBuffer = size;
|
/* probably due to a bug GetServiceDisplayNameA doesn't modify lpcchBuffer on success.
|
||||||
|
* (but if the function succeeded it means that is a good upper estimation of the size) */
|
||||||
|
ret = TRUE;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
|
HeapFree(GetProcessHeap(), 0, lpDisplayNameW);
|
||||||
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
|
HeapFree(GetProcessHeap(), 0, lpServiceNameW);
|
||||||
|
|
||||||
SetLastError(GLE);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,10 +444,17 @@ static void test_get_displayname(void)
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||||
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
||||||
|
tempsize = displaysize;
|
||||||
|
|
||||||
|
displaysize = 0;
|
||||||
|
ret = GetServiceDisplayNameA(scm_handle, spooler, NULL, &displaysize);
|
||||||
|
ok(!ret, "Expected failure\n");
|
||||||
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||||
|
"Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
|
||||||
|
ok(displaysize == tempsize, "Buffer size mismatch (%d vs %d)\n", tempsize, displaysize);
|
||||||
|
|
||||||
/* Buffer is too small */
|
/* Buffer is too small */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
tempsize = displaysize;
|
|
||||||
displaysize = (tempsize / 2);
|
displaysize = (tempsize / 2);
|
||||||
ret = GetServiceDisplayNameA(scm_handle, spooler, displayname, &displaysize);
|
ret = GetServiceDisplayNameA(scm_handle, spooler, displayname, &displaysize);
|
||||||
ok(!ret, "Expected failure\n");
|
ok(!ret, "Expected failure\n");
|
||||||
|
|
Loading…
Reference in New Issue