From fd3a9b2c2338c9bc9ed5f0b89d58671e8516afac Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 1 Feb 2024 15:51:46 -0500 Subject: [PATCH] Fix UTF16PtrFromString usage --- pkg/log/eventlog/writer_windows.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/log/eventlog/writer_windows.go b/pkg/log/eventlog/writer_windows.go index f4a61028eb..870d1a4052 100644 --- a/pkg/log/eventlog/writer_windows.go +++ b/pkg/log/eventlog/writer_windows.go @@ -31,9 +31,16 @@ func openHandle(host, source string) (h windows.Handle, err error) { } var s *uint16 if host != "" { - s = syscall.UTF16PtrFromString(host) + s, err = syscall.UTF16PtrFromString(host) + if err != nil { + return h, err + } } - h, err = windows.RegisterEventSource(s, syscall.UTF16PtrFromString(source)) + srcPtr, err := syscall.UTF16PtrFromString(source) + if err != nil { + return h, err + } + h, err = windows.RegisterEventSource(s, srcPtr) return h, err } @@ -46,7 +53,11 @@ func (w *Writer) Close() error { } func (w *Writer) Write(p []byte) (n int, err error) { - ss := []*uint16{syscall.UTF16PtrFromString(string(p))} + ptr, err := syscall.UTF16PtrFromString(string(p)) + if err != nil { + 0, return err + } + ss := []*uint16{ptr} // always report as Info. Launcher logs as either info or debug, but the event log does not // appear to have a debug level. err = windows.ReportEvent(w.handle, windows.EVENTLOG_INFORMATION_TYPE, 0, 1, 0, 1, 0, &ss[0], nil)