only allocate a buffer in StartServiceA when dwNumServiceArgs > 0

adjust the image path in services/rpcserver

svn path=/trunk/; revision=31761
This commit is contained in:
Christoph von Wittich 2008-01-13 14:22:55 +00:00
parent 16f2303c0b
commit ea6661ca60
2 changed files with 35 additions and 25 deletions

View file

@ -1058,17 +1058,24 @@ ScmrCreateServiceW(handle_t BindingHandle,
if (dwServiceType & SERVICE_DRIVER)
{
/* FIXME: Adjust the image path */
lpImagePath = (WCHAR*) HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
(wcslen(lpBinaryPathName) + 1) * sizeof(WCHAR));
(wcslen(lpBinaryPathName) + 5) * sizeof(WCHAR));
if (lpImagePath == NULL)
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}
wcscpy(lpImagePath, lpBinaryPathName);
if (lpBinaryPathName[1] == L':')
{
wcscpy(lpImagePath, L"\\??\\");
wcscat(lpImagePath, lpBinaryPathName);
}
else
{
wcscpy(lpImagePath, lpBinaryPathName);
}
}
/* Allocate a new service entry */

View file

@ -1998,34 +1998,36 @@ StartServiceA(SC_HANDLE hService,
DWORD dwNumServiceArgs,
LPCSTR *lpServiceArgVectors)
{
LPSTR lpBuffer;
LPSTR lpBuffer = NULL;
LPSTR lpStr;
DWORD dwError;
DWORD dwBufSize;
DWORD dwBufSize = 0;
DWORD i;
dwBufSize = 0;
for (i = 0; i < dwNumServiceArgs; i++)
if (dwNumServiceArgs > 0)
{
dwBufSize += (strlen(lpServiceArgVectors[i]) + 1);
}
dwBufSize++;
DPRINT1("dwBufSize: %lu\n", dwBufSize);
for (i = 0; i < dwNumServiceArgs; i++)
{
dwBufSize += (strlen(lpServiceArgVectors[i]) + 1);
}
dwBufSize++;
DPRINT1("dwBufSize: %lu\n", dwBufSize);
lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufSize);
if (lpBuffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
lpBuffer = HeapAlloc(GetProcessHeap(), 0, dwBufSize);
if (lpBuffer == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
lpStr = lpBuffer;
for (i = 0; i < dwNumServiceArgs; i++)
{
strcpy(lpStr, lpServiceArgVectors[i]);
lpStr += (strlen(lpServiceArgVectors[i]) + 1);
lpStr = lpBuffer;
for (i = 0; i < dwNumServiceArgs; i++)
{
strcpy(lpStr, lpServiceArgVectors[i]);
lpStr += (strlen(lpServiceArgVectors[i]) + 1);
}
*lpStr = 0;
}
*lpStr = 0;
dwError = ScmrStartServiceA(BindingHandle,
(unsigned int)hService,
@ -2033,7 +2035,8 @@ StartServiceA(SC_HANDLE hService,
(unsigned char *)lpBuffer,
dwBufSize);
HeapFree(GetProcessHeap(), 0, lpBuffer);
if (lpBuffer != NULL)
HeapFree(GetProcessHeap(), 0, lpBuffer);
if (dwError != ERROR_SUCCESS)
{