Skip to content

x/sys/windows/svc/eventlog: Log functions panic if the string is invalid #73006

Closed
@tekkamanendless

Description

@tekkamanendless

Go version

go version go1.23.4 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/XXXX/.cache/go-build'
GOENV='/home/XXXX/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/XXXX/go/pkg/mod'
GONOPROXY='github.com/XXXX/*'
GONOSUMDB='github.com/XXXX/*'
GOOS='linux'
GOPATH='/home/XXXX/go'
GOPRIVATE='github.com/XXXX/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/XXXX/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/XXXX/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.6'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/XXXX/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/XXXX/XXXX/src/github.com/XXXX/agent/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2989788070=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Calling Info (and the other logging functions) will panic if the message contains a character that StringToUTF16 does not like. In particular, the docs say that 0x0 will cause it to panic.

Example:

loggerName := "my-logger"
wlog, err := eventlog.Open(loggerName)
if err != nil {
	// Setup Windows Event log with the log source name and logging levels.
	err = eventlog.InstallAsEventCreate(loggerName, eventlog.Info|eventlog.Warning|eventlog.Error)
	if err != nil {
		panic(err)
	}

	// Open a handler to the event logger.
	wlog, err = eventlog.Open(loggerName)
	if err != nil {
		panic(err)
	}
}

message := string([]byte{0x97, 0x00, 0x98})
wlog.Info(1, message) // This line will panic.

What did you see happen?

panic: syscall: string with NUL passed to StringToUTF16

What did you expect to see?

No output, no panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixPendingIssues that have a fix which has not yet been reviewed or submitted.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions