-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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 token.Environ() unicode bug #65055
Comments
blockp = unsafe.Add(blockp, 2*(len(entry)+1))
// len(entry) is utf8 byte length, not utf16 char length
// A quick fix can be done like this, but not very efficient
// blockp = unsafe.Add(blockp, 2*(len([]rune(entry))+1)) // Returns a default environment associated with the token, rather than the current
// process. If inheritExisting is true, then this environment also inherits the
// environment of the current process.
func (token Token) Environ(inheritExisting bool) (env []string, err error) {
var block *uint16
err = CreateEnvironmentBlock(&block, token, inheritExisting)
if err != nil {
return nil, err
}
defer DestroyEnvironmentBlock(block)
blockp := unsafe.Pointer(block)
for {
entry := UTF16PtrToString((*uint16)(blockp))
if len(entry) == 0 {
break
}
env = append(env, entry)
blockp = unsafe.Add(blockp, 2*(len(entry)+1))
}
return env, nil
} |
@xuyang2, if your program calls (@golang/windows) |
this is what i got:
func readEnvironmentBlock(block *uint16) []uint16 {
var wchars []uint16
ptr := unsafe.Pointer(block)
sz := unsafe.Sizeof(*block)
for {
wchar := *(*uint16)(ptr)
wchars = append(wchars, wchar)
// up to the terminating `\0\0`
if len(wchars) >= 2 && wchars[len(wchars)-2] == 0 && wchars[len(wchars)-1] == 0 {
break
}
ptr = unsafe.Pointer(uintptr(ptr) + sz)
}
return wchars
} |
Oh, yeah. There's the bug:
The simplest fix is probably to parse |
@bcmills, It's my first time contributing to go, and I am willing to work on this issue if that's ok. |
That would be great! I would recommend using the Gerrit workflow described in https://go.dev/doc/contribute#sending_a_change_gerrit. |
Change https://go.dev/cl/556895 mentions this issue: |
Change https://go.dev/cl/557975 mentions this issue: |
This test imports the "slices" package, which did not exist in Go 1.20. The test passes on Go 1.21 and above, and the behavior of the function under test is unlikely to vary by platform, so it doesn't seem worth refactoring the test to work with older releases. Updates golang/go#65055. Fixes golang/go#65223. Change-Id: I5f32106d6057b779579a87750633bc57f97fe152 Cq-Include-Trybots: luci.golang.try:x_sys-go1.20-windows-386,x_sys-go1.20-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/sys/+/557975 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
golang/sys@c3fa2b8#diff-fb27a88ff9c20c84f3069100c4e8a2ed22d813705f4f6be31110b9340a404eeaR49 |
@kmirzavaziri, my bad, you're right. I didn't notice that std also changed from |
Go version
go version go1.20.12 windows/amd64
Output of
go env
in your module/workspace:What did you do?
Set a non-ASCII
JAVA_HOME
system environment variableRun a command prompt in the Local System context
PsExec.exe -s -i cmd.exe
https://learn.microsoft.com/en-us/sysinternals/downloads/sysinternals-suite
Compile and run this
What did you see happen?
with some env entry omitted:
What did you expect to see?
The text was updated successfully, but these errors were encountered: