Skip to content

Commit

Permalink
[SERVICES] Use pointers to const string (PCWSTR) instead of non-const…
Browse files Browse the repository at this point in the history
… for argv
  • Loading branch information
HBelusca committed Oct 11, 2024
1 parent 0f7b021 commit fe66aa8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
11 changes: 6 additions & 5 deletions base/system/services/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ ScmControlServiceEx(
_In_ SERVICE_STATUS_HANDLE hServiceStatus,
_In_opt_ DWORD dwServiceTag,
_In_opt_ DWORD argc,
_In_reads_opt_(argc) PWSTR* argv)
_In_reads_opt_(argc) const PCWSTR* argv)
{
DWORD dwError = ERROR_SUCCESS;
BOOL bResult;
Expand Down Expand Up @@ -1813,7 +1813,7 @@ ScmWaitForServiceConnect(PSERVICE Service)
static DWORD
ScmStartUserModeService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
PROCESS_INFORMATION ProcessInformation;
STARTUPINFOW StartupInfo;
Expand Down Expand Up @@ -1963,7 +1963,7 @@ ScmStartUserModeService(PSERVICE Service,
static DWORD
ScmLoadService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
PSERVICE_GROUP Group = Service->lpGroup;
DWORD dwError = ERROR_SUCCESS;
Expand Down Expand Up @@ -2076,7 +2076,7 @@ ScmLoadService(PSERVICE Service,
DWORD
ScmStartService(PSERVICE Service,
DWORD argc,
LPWSTR* argv)
const PCWSTR* argv)
{
DWORD dwError = ERROR_SUCCESS;
SC_RPC_LOCK Lock = NULL;
Expand All @@ -2095,7 +2095,8 @@ ScmStartService(PSERVICE Service,
if (!ScmInitialize)
{
dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
if (dwError != ERROR_SUCCESS) goto done;
if (dwError != ERROR_SUCCESS)
goto done;
}

/* Really start the service */
Expand Down
36 changes: 18 additions & 18 deletions base/system/services/rpcserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,7 @@ RStartServiceW(
return ERROR_SERVICE_MARKED_FOR_DELETE;

/* Start the service */
dwError = ScmStartService(lpService, argc, (LPWSTR*)argv);
dwError = ScmStartService(lpService, argc, (PCWSTR*)argv);

return dwError;
}
Expand Down Expand Up @@ -4378,7 +4378,7 @@ RStartServiceA(
DWORD dwError = ERROR_SUCCESS;
PSERVICE_HANDLE hSvc;
PSERVICE lpService = NULL;
LPWSTR *lpVector = NULL;
PWSTR* pVector = NULL;
DWORD i;
DWORD dwLength;

Expand Down Expand Up @@ -4417,52 +4417,52 @@ RStartServiceA(
/* Build a Unicode argument vector */
if (argc > 0)
{
lpVector = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
argc * sizeof(LPWSTR));
if (lpVector == NULL)
pVector = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
argc * sizeof(PWSTR));
if (!pVector)
return ERROR_NOT_ENOUGH_MEMORY;

for (i = 0; i < argc; i++)
{
dwLength = MultiByteToWideChar(CP_ACP,
0,
((LPSTR*)argv)[i],
argv[i].StringPtr,
-1,
NULL,
0);

lpVector[i] = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwLength * sizeof(WCHAR));
if (lpVector[i] == NULL)
pVector[i] = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
dwLength * sizeof(WCHAR));
if (!pVector[i])
{
dwError = ERROR_NOT_ENOUGH_MEMORY;
goto done;
}

MultiByteToWideChar(CP_ACP,
0,
((LPSTR*)argv)[i],
argv[i].StringPtr,
-1,
lpVector[i],
pVector[i],
dwLength);
}
}

/* Start the service */
dwError = ScmStartService(lpService, argc, lpVector);
dwError = ScmStartService(lpService, argc, (PCWSTR*)pVector);

done:
/* Free the Unicode argument vector */
if (lpVector != NULL)
if (pVector)
{
for (i = 0; i < argc; i++)
{
if (lpVector[i] != NULL)
HeapFree(GetProcessHeap(), 0, lpVector[i]);
if (pVector[i])
HeapFree(GetProcessHeap(), 0, pVector[i]);
}
HeapFree(GetProcessHeap(), 0, lpVector);
HeapFree(GetProcessHeap(), 0, pVector);
}

return dwError;
Expand Down
2 changes: 1 addition & 1 deletion base/system/services/services.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ VOID ScmAutoStartServices(VOID);
VOID ScmAutoShutdownServices(VOID);
DWORD ScmStartService(PSERVICE Service,
DWORD argc,
LPWSTR *argv);
const PCWSTR* argv);

DWORD ScmReferenceService(PSERVICE lpService);
DWORD ScmDereferenceService(PSERVICE lpService);
Expand Down

0 comments on commit fe66aa8

Please sign in to comment.