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) if (dwServiceType & SERVICE_DRIVER)
{ {
/* FIXME: Adjust the image path */
lpImagePath = (WCHAR*) HeapAlloc(GetProcessHeap(), lpImagePath = (WCHAR*) HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
(wcslen(lpBinaryPathName) + 1) * sizeof(WCHAR)); (wcslen(lpBinaryPathName) + 5) * sizeof(WCHAR));
if (lpImagePath == NULL) if (lpImagePath == NULL)
{ {
dwError = ERROR_NOT_ENOUGH_MEMORY; dwError = ERROR_NOT_ENOUGH_MEMORY;
goto done; goto done;
} }
wcscpy(lpImagePath, lpBinaryPathName);
if (lpBinaryPathName[1] == L':')
{
wcscpy(lpImagePath, L"\\??\\");
wcscat(lpImagePath, lpBinaryPathName);
}
else
{
wcscpy(lpImagePath, lpBinaryPathName);
}
} }
/* Allocate a new service entry */ /* Allocate a new service entry */

View file

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