golang-design / clipboard

📋 cross-platform clipboard package that supports accessing text and image in Go (macOS/Linux/Windows/Android/iOS)
https://golang.design/x/clipboard
MIT License
630 stars 68 forks source link

Segmentation violation using the gclip tool on Fedora #27

Open CmdrNorthpaw opened 2 years ago

CmdrNorthpaw commented 2 years ago

I have been using clipboard to build a small personal application as a replacement for xclip. The first time I built and tested the application, it threw this error:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw({0x4bc05d?, 0x1?})
        /usr/local/go/src/runtime/panic.go:992 +0x71
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:802 +0x3a9

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4996f0, 0xc00006fde8)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc00006fdc0 sp=0xc00006fd88 pc=0x40521c
golang.design/x/clipboard._Cfunc_clipboard_test()
        _cgo_gotypes.go:93 +0x48 fp=0xc00006fde8 sp=0xc00006fdc0 pc=0x498028
golang.design/x/clipboard.initialize()
        /home/$USER/.go/pkg/mod/golang.design/x/clipboard@v0.6.2/clipboard_linux.go:60 +0x1d fp=0xc00006fe30 sp=0xc00006fde8 pc=0x49829d
golang.design/x/clipboard.Init(...)
        /home/$USER/.go/pkg/mod/golang.design/x/clipboard@v0.6.2/clipboard.go:102
main.init.0()
        /home/$USER/.go/pkg/mod/golang.design/x/clipboard@v0.6.2/cmd/gclip/main.go:47 +0x1a fp=0xc00006fe50 sp=0xc00006fe30 pc=0x49903a
runtime.doInit(0x546a00)
        /usr/local/go/src/runtime/proc.go:6222 +0x126 fp=0xc00006ff80 sp=0xc00006fe50 pc=0x4429e6
runtime.main()
        /usr/local/go/src/runtime/proc.go:233 +0x1d3 fp=0xc00006ffe0 sp=0xc00006ff80 pc=0x435a93
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc00006ffe8 sp=0xc00006ffe0 pc=0x45ebc1

I thought it was an issue with my code, but the gclip reference tool throws the same error, so I must assume that the issue lies with the clipboard library. My /etc/os-release file (unsure if this helps):


VERSION="35 (KDE Plasma)"
ID=fedora
VERSION_ID=35
VERSION_CODENAME=""
PLATFORM_ID="platform:f35"
PRETTY_NAME="Fedora Linux 35 (KDE Plasma)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:35"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f35/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=35
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=35
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="KDE Plasma"
VARIANT_ID=kde```
changkun commented 2 years ago

Thanks for the report. Unfortunately, we do not have a fedora system to test this issue. We would have to rely on the community to tackle this issue.

Contributions are welcome.

evilsocket commented 2 years ago

this might depend by two things, either P_XOpenDisplay is NULL but doesn't get checked before being used here, or the $DISPLAY environment variable is not set (if the argument of XOpenDisplay is NULL as in this case, $DISPLAY is used instead).

evilsocket commented 2 years ago

Just did a quick test and if the function pointer is correctly initialized, it shouldn't crash even if $DISPLAY is not set ... so there's a good chance that this SIGSEGV is caused by the function pointer being NULL (also hinted by that addr=0x0 pc=0x0). I suggest to check for those pointers in the initX11 function and return 1 only if they are all set. Also what's the point of looping 42 times? :D

image

zangarmarsh commented 2 years ago

@changkun I confirm this bug is not specifically related to Fedora.

changkun commented 2 years ago

@zangarmarsh Thanks for confirming the issue. Could you maybe share more details on how to reproduce the issue? More specifically, which environment, in which steps that you did?

zangarmarsh commented 2 years ago

@changkun It occurs in Ubuntu X11. I also tried in wayland and it works correctly.

changkun commented 2 years ago

@zangarmarsh Is the problem occurring on the latest commit?

zangarmarsh commented 2 years ago

@changkun I updated it to version 0.6.3 and it works! Thank you.