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

cmd/cgo: crash when function received string with chinese characters #29653

Closed
tangliming opened this issue Jan 10, 2019 · 3 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@tangliming
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.11 windows/3

Does this issue reproduce with the latest release?

currently 1.11 is the latest release

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=e:\gowork
set GOPROXY=
set GORACE=
set GOROOT=E:\Go
set GOTMPDIR=
set GOTOOLDIR=E:\Go\pkg\tool\windows_386
set GCCGO=gccgo
set GO386=sse2
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build173954786=/tmp/go-build -gno-record-gcc-switches

What did you do?

I have a wrapper function in C file.
void initBlink(char *dllpath, char *localstorage, char *cookiejar)

and call it in other go file.
C.initBlink( C.CString(dllPath), C.CString(TempPath), C.CString(filepath.Join(TempPath, "cookie.dat")), )

What did you expect to see?

I expect it to run normally.

What did you see instead?

if the dllPath or TempPath has chinese characters, progrom will crash with below output
`
Exception 0xc0000005 0x0 0x0 0x0
PC=0x0
signal arrived during external code execution

github.com/raintean/blink._Cfunc_initBlink(0x2113c08, 0x2113c50, 0x2113c88)
_cgo_gotypes.go:138 +0x33
github.com/raintean/blink.InitBlink.func2(0x13c16200, 0x39)
e:/gowork/src/github.com/raintean/blink/blink.go:59 +0xc1
created by github.com/raintean/blink.InitBlink
e:/gowork/src/github.com/raintean/blink/blink.go:54 +0x212

goroutine 1 [syscall, locked to thread]:
syscall.Syscall9(0x751e4340, 0x7, 0x300, 0x13c105b0, 0x13c6b360, 0x400, 0x13c6b354, 0x0, 0x13db6120, 0x0, ...)
E:/Go/src/runtime/syscall_windows.go:198 +0xcf
internal/syscall/windows/registry.regLoadMUIString(0x324, 0x13c10630, 0x400, 0x13da6940, 0xf, 0x0, 0x13db6480, 0x0, 0x0)
E:/Go/src/internal/syscall/windows/registry/zsyscall_windows.go:92 +0xa3
fatal error: unexpected signal during runtime execution
[signal 0xc0000005 code=0x0 addr=0x89 pc=0x444f7f]

runtime stack:
runtime: unexpected return pc for runtime.sigtramp called from 0x33fff96c
stack: frame={sp:0x33fff73c, fp:0x33fff740} stack=[0x0,0x33ffff28)
33fff6bc: 0040957d <runtime.unlock+93> 012782b0 00000000 00445bd1 <runtime.traceback+65>
33fff6cc: 0040389f <runtime.cgocall+95> 13c6b2b8 00000000 13c24000
33fff6dc: 00000000 00446d58 <runtime.tracebackothers+328> ffffffff ffffffff
33fff6ec: 00000000 13c24000 00000001 00000000
33fff6fc: 0000000d 13c24000 00000000 13c24460
33fff70c: 13c82ac0 00439738 <runtime.lastcontinuehandler+504> 13c249a0 33fffe9c
33fff71c: 00000000 13c249a0 00000000 00000000
33fff72c: 00000000 00000000 13c24460 0044ed00 <runtime.sigtramp+128>
33fff73c: <33fff96c >33fff9bc 13c249a0 0044ed40 <runtime.lastcontinuetramp+0>
33fff74c: 33fff7fc 00000000 0044ed40 <runtime.lastcontinuetramp+0> 33fff82c
33fff75c: 13c24460 33fff73c 76bd5cf0 33fff82c
33fff76c: fe4c53c7 00000000 76bd5b50 00000000
33fff77c: 00000000 7528ca20 00000001 00000000
33fff78c: 00000000 00000006 33fff82c 00000004
33fff79c: 00000000 02113cc8 00000000 00000000
33fff7ac: 00000000 02113c08 77bbb569 0000002b
33fff7bc: 00000000
runtime.throw(0xf06358, 0x2a)
E:/Go/src/runtime/panic.go:608 +0x64
runtime.sigpanic()
E:/Go/src/runtime/signal_windows.go:198 +0x14d
runtime.gentraceback(0x40389f, 0x13c6b2b8, 0x0, 0x13c24000, 0x0, 0x0, 0x64, 0x0, 0x0, 0x0, ...)
E:/Go/src/runtime/traceback.go:249 +0x113f
runtime.traceback1(0x40389f, 0x13c6b2b8, 0x0, 0x13c24000, 0x0)
E:/Go/src/runtime/traceback.go:719 +0xef
runtime.traceback(0xffffffff, 0xffffffff, 0x0, 0x13c24000)
E:/Go/src/runtime/traceback.go:673 +0x41
runtime.tracebackothers(0x13c249a0)
E:/Go/src/runtime/traceback.go:938 +0x148
runtime.lastcontinuehandler(0x33fff96c, 0x33fff9bc, 0x13c249a0, 0x44ed40)
E:/Go/src/runtime/signal_windows.go:183 +0x1f8
runtime: unexpected return pc for runtime.sigtramp called from 0x33fff96c
stack: frame={sp:0x33fff73c, fp:0x33fff740} stack=[0x0,0x33ffff28)
33fff6bc: 0040957d <runtime.unlock+93> 012782b0 00000000 00445bd1 <runtime.traceback+65>
33fff6cc: 0040389f <runtime.cgocall+95> 13c6b2b8 00000000 13c24000
33fff6dc: 00000000 00446d58 <runtime.tracebackothers+328> ffffffff ffffffff
33fff6ec: 00000000 13c24000 00000001 00000000
33fff6fc: 0000000d 13c24000 00000000 13c24460
33fff70c: 13c82ac0 00439738 <runtime.lastcontinuehandler+504> 13c249a0 33fffe9c
33fff71c: 00000000 13c249a0 00000000 00000000
33fff72c: 00000000 00000000 13c24460 0044ed00 <runtime.sigtramp+128>
33fff73c: <33fff96c >33fff9bc 13c249a0 0044ed40 <runtime.lastcontinuetramp+0>
33fff74c: 33fff7fc 00000000 0044ed40 <runtime.lastcontinuetramp+0> 33fff82c
33fff75c: 13c24460 33fff73c 76bd5cf0 33fff82c
33fff76c: fe4c53c7 00000000 76bd5b50 00000000
33fff77c: 00000000 7528ca20 00000001 00000000
33fff78c: 00000000 00000006 33fff82c 00000004
33fff79c: 00000000 02113cc8 00000000 00000000
33fff7ac: 00000000 02113c08 77bbb569 0000002b
33fff7bc: 00000000
runtime.sigtramp()
E:/Go/src/runtime/sys_windows_386.s:133 +0x80

goroutine 6 [syscall, locked to thread]:
runtime.cgocall(0x7a46b0, 0x13d6ff80, 0x36)
E:/Go/src/runtime/cgocall.go:128 +0x5f fp=0x13d6ff6c sp=0x13d6ff54 pc=0x40389f
github.com/raintean/blink._Cfunc_initBlink(0x2113c08, 0x2113c50, 0x2113c88)
_cgo_gotypes.go:138 +0x33 fp=0x13d6ff80 sp=0x13d6ff6c pc=0x796d63
github.com/raintean/blink.InitBlink.func2(0x13c16200, 0x39)
e:/gowork/src/github.com/raintean/blink/blink.go:59 +0xc1 fp=0x13d6ffe8 sp=0x13d6ff80 pc=0x79a271
runtime.goexit()
E:/Go/src/runtime/asm_386.s:1324 +0x1 fp=0x13d6ffec sp=0x13d6ffe8 pc=0x44e1d1
created by github.com/raintean/blink.InitBlink
e:/gowork/src/github.com/raintean/blink/blink.go:54 +0x212
`

@tangliming
Copy link
Author

How can I fix this issue?

@ALTree ALTree changed the title cgo crash when function received string with chinese characters cmd/cgo: crash when function received string with chinese characters Jan 10, 2019
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 10, 2019
@ALTree ALTree added this to the Go1.13 milestone Jan 10, 2019
@sabhiram
Copy link

Not a windows registry expert, but it almost feels like this is not a go issue per se.

The call stack indicates that something went wrong when something down-stream from your blink code decided to invoke regLoadMUIString (see https://golang.org/src/internal/syscall/windows/registry/zsyscall_windows.go). My guess is that one of the char buffers needs to be some form of sanitization before being sent to the syscall. Perhaps this is some type of wchar issue.

One useful thing to help diagnose would be to see if you can reproduce the same issue without using any of the cgo stuff (from pure C land). My guess is you will still have the same issue regardless of cgo as your C function accepts a simple char * which might not play nice with some of the windows registry stuff.

@ianlancetaylor
Copy link
Contributor

This is a crash in your C code. There's no obvious reason to think that this is a problem with Go.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 11, 2019
@golang golang locked and limited conversation to collaborators Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants