From 62505586fcc10b7187767f58357bcf1fd23ba1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sat, 28 Sep 2024 20:28:57 +0200 Subject: [PATCH] [ADVAPI32] StartServiceCtrlDispatcherA/W(): Check the names of services when counting them. Fail also if none were found. --- dll/win32/advapi32/service/sctrl.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/dll/win32/advapi32/service/sctrl.c b/dll/win32/advapi32/service/sctrl.c index c8f02db845ac8..36afc66896713 100644 --- a/dll/win32/advapi32/service/sctrl.c +++ b/dll/win32/advapi32/service/sctrl.c @@ -1061,14 +1061,23 @@ StartServiceCtrlDispatcherA(const SERVICE_TABLE_ENTRYA *lpServiceStartTable) return FALSE; } + /* Count the number of active services. They must + * have a "valid" name and service procedure. */ i = 0; - while (lpServiceStartTable[i].lpServiceProc != NULL) + while (lpServiceStartTable[i].lpServiceName != NULL && + lpServiceStartTable[i].lpServiceProc != NULL) { - i++; + ++i; } - dwActiveServiceCount = i; + /* If no active services were found, fail the call */ + if (!dwActiveServiceCount) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + /* Allocate the service table */ lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, @@ -1151,14 +1160,23 @@ StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable) return FALSE; } + /* Count the number of active services. They must + * have a "valid" name and service procedure. */ i = 0; - while (lpServiceStartTable[i].lpServiceProc != NULL) + while (lpServiceStartTable[i].lpServiceName != NULL && + lpServiceStartTable[i].lpServiceProc != NULL) { - i++; + ++i; } - dwActiveServiceCount = i; + /* If no active services were found, fail the call */ + if (!dwActiveServiceCount) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + /* Allocate the service table */ lpActiveServices = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY,