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

Fix crash on 64 bit Linux in command line argument parsing #297

Merged
merged 1 commit into from Jan 9, 2017

Conversation

ptriller
Copy link
Contributor

@ptriller ptriller commented Jan 8, 2017

On my Ubuntu 16.04 the command line parsing fails with SIGSEGV (see below)

The code to fix it was inspired by https://github.com/gotk3/gotk3 and ported to you. It seems you already had the necessary C functions, so the patch is minimal.

ptriller@nuc:~/go-workspace/src/github.com/mattn/go-gtk/example/demo$ go build demo.go 
ptriller@nuc:~/go-workspace/src/github.com/mattn/go-gtk/example/demo$ gdb ./demo 
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./demo...done.
warning: File "/home/ptriller/Programs/go/src/runtime/runtime-gdb.py" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
	add-auto-load-safe-path /home/ptriller/Programs/go/src/runtime/runtime-gdb.py
line to your configuration file "/home/ptriller/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/ptriller/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
(gdb) run
Starting program: /home/ptriller/go-workspace/src/github.com/mattn/go-gtk/example/demo/demo 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff1017700 (LWP 27922)]
[New Thread 0x7ffff0816700 (LWP 27923)]
[New Thread 0x7ffff0015700 (LWP 27924)]
[New Thread 0x7fffef814700 (LWP 27925)]

Thread 1 "demo" received signal SIGSEGV, Segmentation fault.
0x00007ffff76884bd in g_path_get_basename () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
(gdb) bt
#0  0x00007ffff76884bd in g_path_get_basename () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#1  0x00007ffff76a6531 in g_option_context_parse () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007ffff71364b8 in gtk_parse_args () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#3  0x00007ffff7136539 in gtk_init () from /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0
#4  0x0000000000495050 in runtime.asmcgocall () at /home/ptriller/Programs/go/src/runtime/asm_amd64.s:590
#5  0x00000000004421ad in runtime.cgocall (fn=0x7fffffffdb30, arg=0x9f1620 <runtime.g0>, ~r2=-9440) at /home/ptriller/Programs/go/src/runtime/cgocall.go:115
#6  0x00000000009f1600 in runtime.work ()
#7  0x00007fffffffdb30 in ?? ()
#8  0x00000000009f1620 in ?? ()
#9  0x00007fffffffdb20 in ?? ()
#10 0x000000000046c744 in runtime.mstart () at /home/ptriller/Programs/go/src/runtime/proc.go:1096
#11 0x00000000004931a5 in runtime.rt0_go () at /home/ptriller/Programs/go/src/runtime/asm_amd64.s:156
#12 0x0000000000000001 in ?? ()
#13 0x00007fffffffdc38 in ?? ()
#14 0x0000000000000001 in ?? ()
#15 0x00007fffffffdc38 in ?? ()
#16 0x0000000000000000 in ?? ()
(gdb) quit
A debugging session is active.

	Inferior 1 [process 27918] will be killed.

Quit anyway? (y or n) y
ptriller@nuc:~/go-workspace/src/github.com/mattn/go-gtk/example/demo$ 

@mattn mattn merged commit b9d8404 into mattn:master Jan 9, 2017
@mattn
Copy link
Owner

mattn commented Jan 9, 2017

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants