Skip to content

Commit 7015c76

Browse files
committed
[ADVAPI32] Do not call the classic service handler function with an event control code
1 parent d4c6477 commit 7015c76

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

dll/win32/advapi32/service/sctrl.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ ScControlService(PACTIVE_SERVICE lpService,
551551
PSCM_CONTROL_PACKET ControlPacket)
552552
{
553553
DWORD dwError = ERROR_SUCCESS;
554+
DWORD dwControl;
554555
DWORD dwEventType = 0;
555556
PVOID pEventData = NULL;
556557

@@ -566,29 +567,39 @@ ScControlService(PACTIVE_SERVICE lpService,
566567
/* Set service tag */
567568
NtCurrentTeb()->SubProcessTag = UlongToPtr(lpService->dwServiceTag);
568569

570+
dwControl = ControlPacket->dwControl;
571+
569572
if (lpService->HandlerFunction)
570573
{
571-
_SEH2_TRY
574+
if (((dwControl >= SERVICE_CONTROL_STOP) && (dwControl <= SERVICE_CONTROL_NETBINDDISABLE)) ||
575+
((dwControl >= 128) && (dwControl <= 255)))
572576
{
573-
(lpService->HandlerFunction)(ControlPacket->dwControl);
577+
_SEH2_TRY
578+
{
579+
(lpService->HandlerFunction)(dwControl);
580+
}
581+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
582+
{
583+
dwError = ERROR_EXCEPTION_IN_SERVICE;
584+
}
585+
_SEH2_END;
574586
}
575-
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
587+
else
576588
{
577-
dwError = ERROR_EXCEPTION_IN_SERVICE;
589+
dwError = ERROR_INVALID_SERVICE_CONTROL;
578590
}
579-
_SEH2_END;
580591
}
581592
else if (lpService->HandlerFunctionEx)
582593
{
583-
if (ControlPacket->dwControl == SERVICE_CONTROL_DEVICEEVENT)
594+
if (dwControl == SERVICE_CONTROL_DEVICEEVENT)
584595
{
585596
dwEventType = *(LPDWORD)((ULONG_PTR)ControlPacket + sizeof(SCM_CONTROL_PACKET));
586597
pEventData = (PVOID)((ULONG_PTR)ControlPacket + sizeof(SCM_CONTROL_PACKET) + sizeof(DWORD));
587598
}
588599

589600
_SEH2_TRY
590601
{
591-
(lpService->HandlerFunctionEx)(ControlPacket->dwControl,
602+
(lpService->HandlerFunctionEx)(dwControl,
592603
dwEventType,
593604
pEventData,
594605
lpService->HandlerContext);

0 commit comments

Comments
 (0)