mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -04:00
windows/svc: do not pass theService to windows.RegisterServiceCtrlHandlerEx
windows.RegisterServiceCtrlHandlerEx context parameter is uintptr, so it is unsafe to pass pointers in that parameter. Use theService global variable in ctlHandler function instead. Fixes golang/go#67437 Change-Id: I84c910eaa354603c2a5114421cd61788cb40b86f Reviewed-on: https://go-review.googlesource.com/c/sys/+/591475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
@@ -199,9 +199,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ctlHandler(ctl, evtype, evdata, context uintptr) uintptr {
|
func ctlHandler(ctl, evtype, evdata, context uintptr) uintptr {
|
||||||
s := (*service)(unsafe.Pointer(context))
|
|
||||||
e := ctlEvent{cmd: Cmd(ctl), eventType: uint32(evtype), eventData: evdata, context: 123456} // Set context to 123456 to test issue #25660.
|
e := ctlEvent{cmd: Cmd(ctl), eventType: uint32(evtype), eventData: evdata, context: 123456} // Set context to 123456 to test issue #25660.
|
||||||
s.c <- e
|
theService.c <- e
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,7 +209,7 @@ var theService service // This is, unfortunately, a global, which means only one
|
|||||||
// serviceMain is the entry point called by the service manager, registered earlier by
|
// serviceMain is the entry point called by the service manager, registered earlier by
|
||||||
// the call to StartServiceCtrlDispatcher.
|
// the call to StartServiceCtrlDispatcher.
|
||||||
func serviceMain(argc uint32, argv **uint16) uintptr {
|
func serviceMain(argc uint32, argv **uint16) uintptr {
|
||||||
handle, err := windows.RegisterServiceCtrlHandlerEx(windows.StringToUTF16Ptr(theService.name), ctlHandlerCallback, uintptr(unsafe.Pointer(&theService)))
|
handle, err := windows.RegisterServiceCtrlHandlerEx(windows.StringToUTF16Ptr(theService.name), ctlHandlerCallback, 0)
|
||||||
if sysErr, ok := err.(windows.Errno); ok {
|
if sysErr, ok := err.(windows.Errno); ok {
|
||||||
return uintptr(sysErr)
|
return uintptr(sysErr)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user