clipboard icon indicating copy to clipboard operation
clipboard copied to clipboard

Segmentation violation using the gclip tool on Fedora

Open CmdrNorthpaw opened this issue 3 years ago • 8 comments

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/[email protected]/clipboard_linux.go:60 +0x1d fp=0xc00006fe30 sp=0xc00006fde8 pc=0x49829d
golang.design/x/clipboard.Init(...)
        /home/$USER/.go/pkg/mod/golang.design/x/[email protected]/clipboard.go:102
main.init.0()
        /home/$USER/.go/pkg/mod/golang.design/x/[email protected]/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```

CmdrNorthpaw avatar Apr 28 '22 11:04 CmdrNorthpaw

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.

changkun avatar Apr 28 '22 12:04 changkun

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 avatar Sep 10 '22 10:09 evilsocket

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

evilsocket avatar Sep 10 '22 10:09 evilsocket

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

zangarmarsh avatar Sep 20 '22 07:09 zangarmarsh

@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?

changkun avatar Sep 20 '22 11:09 changkun

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

zangarmarsh avatar Nov 02 '22 15:11 zangarmarsh

@zangarmarsh Is the problem occurring on the latest commit?

changkun avatar Nov 02 '22 15:11 changkun

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

zangarmarsh avatar Nov 03 '22 15:11 zangarmarsh