Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tekkamanendless opened this issue Mar 22, 2025 · 3 comments
Closed
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. OS-Windows
Milestone

Comments

@tekkamanendless
Copy link

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.

@gopherbot gopherbot added this to the Unreleased milestone Mar 22, 2025
@ianlancetaylor
Copy link
Member

CC @golang/windows

@tekkamanendless
Copy link
Author

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/659936 mentions this issue: Replace all StringToUTF16 calls with UTF16FromString

@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants