Subject: bug#45277: D-Bus crashes and DND errors

From: Juri Linkov <[email-masked]>
Date: Wed, 16 Dec 2020 22:58:30 +0200

Sometimes DND causes just errors, sometimes D-BUS events cause Emacs crashes.

Here is an example of DND errors when debug-on-error is enabled:

Debugger entered--Lisp error: (error "Bad data in VALUES, must be number, cons or string")
  x-send-client-message(#<frame emacs@localhost 0x555556182a40> 21062611 #<frame emacs@localhost 0x555556182a40> "XdndStatus" 32 (62914762 0 ((+ -1) . 1) 0 0))
  x-dnd-handle-xdnd((drag-n-drop (#<frame emacs@localhost 0x555556182a40> nil (854 . 0) 0) ["XdndPosition" #<frame emacs@localhost 0x555556182a40> 32 [21062611 0 55967771 54687100 550]]) #<frame emacs@localhost 0x555556182a40> #<frame emacs@localhost 0x555556182a40> "XdndPosition" 32 [21062611 0 55967771 54687100 550])
  x-dnd-handle-drag-n-drop-event((drag-n-drop (#<frame emacs@localhost 0x555556182a40> nil (854 . 0) 0) ["XdndPosition" #<frame emacs@localhost 0x555556182a40> 32 [21062611 0 55967771 54687100 550]]))
  funcall-interactively(x-dnd-handle-drag-n-drop-event (drag-n-drop (#<frame emacs@localhost 0x555556182a40> nil (854 . 0) 0) ["XdndPosition" #<frame emacs@localhost 0x555556182a40> 32 [21062611 0 55967771 54687100 550]]))
  call-interactively(x-dnd-handle-drag-n-drop-event nil [(drag-n-drop (#<frame emacs@localhost 0x555556182a40> nil (854 . 0) 0) ["XdndPosition" #<frame emacs@localhost 0x555556182a40> 32 [21062611 0 55967771 54687100 550]])])
  command-execute(x-dnd-handle-drag-n-drop-event nil [(drag-n-drop (#<frame emacs@localhost 0x555556182a40> nil (854 . 0) 0) ["XdndPosition" #<frame emacs@localhost 0x555556182a40> 32 [21062611 0 55967771 54687100 550]])] t)

What is worse are sporadic crashes by dbus-handle-event:

Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
print_preprocess (obj=obj@entry=XIL(0x55556462e080)) at lisp.h:2204
2204	  return XSYMBOL (sym)->u.s.interned != SYMBOL_UNINTERNED;
(gdb) bt
#0  print_preprocess (obj=obj@entry=XIL(0x55556462e080)) at lisp.h:2204
#1  0x000055555572f234 in print (obj=XIL(0x55556462e080), printcharfun=XIL(0x30), escapeflag=<optimized out>) at print.c:1126
#2  0x000055555572f702 in Fprin1 (object=XIL(0x55556462e080), printcharfun=<optimized out>) at print.c:651
#3  0x0000555555730895 in print_error_message (data=<optimized out>, data@entry=XIL(0x555558492423), stream=stream@entry=XIL(0x30), context=<optimized out>, caller=caller@entry=XIL(0x2aaa9c29dce0)) at print.c:977
#4  0x0000555555692547 in Fcommand_error_default_function (data=XIL(0x555558492423), context=XIL(0x7ffff1c52674), signal=XIL(0x2aaa9c29dce0)) at lisp.h:1564
#5  0x000055555570fa9b in Ffuncall (nargs=4, args=0x7fffffffc050) at lisp.h:2081
#6  0x0000555555711b28 in Fapply (nargs=2, args=0x7fffffffc168) at eval.c:2509
#7  0x000055555570fa9b in Ffuncall (nargs=3, args=args@entry=0x7fffffffc160) at lisp.h:2081
#8  0x000055555574cb54 in exec_byte_code (bytestr=<optimized out>, vector=<optimized out>, maxdepth=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at bytecode.c:632
#9  0x000055555570f9d7 in Ffuncall (nargs=4, args=0x7fffffffc430) at eval.c:2893
#10 0x000055555570fc38 in call3 (fn=<optimized out>, arg1=arg1@entry=XIL(0x555558492423), arg2=<optimized out>, arg3=arg3@entry=XIL(0x2aaa9c29dce0)) at eval.c:2753
#11 0x00005555556962e6 in cmd_error_internal (data=data@entry=XIL(0x555558492423), context=context@entry=0x7fffffffc490 "") at lisp.h:3910
#12 0x000055555569642b in cmd_error (data=XIL(0x555558492423)) at keyboard.c:956
#13 0x000055555570eb91 in internal_condition_case (bfun=bfun@entry=0x55555569f9c0 <command_loop_1>, handlers=handlers@entry=XIL(0x90), hfun=hfun@entry=0x555555696310 <cmd_error>) at eval.c:1411
#14 0x00005555556907c4 in command_loop_2 (ignore=ignore@entry=XIL(0)) at lisp.h:1007
#15 0x000055555570eae9 in internal_catch (tag=tag@entry=XIL(0x5c70), func=func@entry=0x5555556907a0 <command_loop_2>, arg=arg@entry=XIL(0)) at eval.c:1176
#16 0x0000555555690719 in command_loop () at lisp.h:1007
#17 0x0000555555695f1a in recursive_edit_1 () at keyboard.c:720
#18 0x0000555555696256 in Frecursive_edit () at keyboard.c:789
#19 0x000055555570fa9b in Ffuncall (nargs=1, args=args@entry=0x7fffffffc700) at lisp.h:2081
#20 0x000055555574cb54 in exec_byte_code (bytestr=<optimized out>, vector=<optimized out>, maxdepth=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at bytecode.c:632
#21 0x000055555570f9d7 in Ffuncall (nargs=3, args=0x7fffffffcbb0) at eval.c:2893
#22 0x0000555555711b28 in Fapply (nargs=nargs@entry=2, args=args@entry=0x7fffffffcc50) at eval.c:2509
#23 0x00005555557101f5 in apply1 (arg=XIL(0x555557ee92a3), fn=<optimized out>) at lisp.h:1373
#24 call_debugger (arg=XIL(0x555557ee92a3)) at eval.c:339
#25 0x000055555571092d in maybe_call_debugger (data=XIL(0x555557ee92d3), sig=<optimized out>, conditions=XIL(0x7ffff1e724fb)) at lisp.h:1007
#26 signal_or_quit (error_symbol=<optimized out>, data=XIL(0x555557ee92d3), keyboard_quit=<optimized out>) at eval.c:1727
#27 0x00005555555a14c2 in Fsignal (error_symbol=<optimized out>, error_symbol@entry=XIL(0xf090), data=<optimized out>) at eval.c:1628
#28 0x00005555555a16a8 in xsignal (data=<optimized out>, error_symbol=XIL(0xf090)) at lisp.h:4115
#29 xsignal2 (error_symbol=error_symbol@entry=XIL(0xf090), arg1=arg1@entry=XIL(0xa7d0), arg2=<optimized out>) at eval.c:1787
#30 0x00005555555a070c in wrong_type_argument (predicate=predicate@entry=XIL(0xa7d0), value=<optimized out>) at lisp.h:1007
#31 0x00005555555a0726 in CHECK_TYPE (x=<optimized out>, predicate=XIL(0xa7d0), ok=0) at lisp.h:758
#32 check_number_coerce_marker (x=<optimized out>) at data.c:2377
#33 0x00005555556fd5cd in arithcompare (num1=make_fixnum(1), num2=XIL(0x8550), comparison=comparison@entry=ARITH_EQUAL) at data.c:2390
#34 0x000055555574ead4 in exec_byte_code (bytestr=<optimized out>, vector=<optimized out>, maxdepth=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at bytecode.c:990
#35 0x000055555570f9d7 in Ffuncall (nargs=nargs@entry=2, args=args@entry=0x7fffffffd218) at eval.c:2893
#36 0x000055555570c175 in Ffuncall_interactively (nargs=2, args=0x7fffffffd218) at callint.c:253
#37 0x000055555570fa9b in Ffuncall (nargs=nargs@entry=3, args=args@entry=0x7fffffffd210) at lisp.h:2081
#38 0x000055555570d68b in Fcall_interactively (function=<optimized out>, record_flag=<optimized out>, keys=<optimized out>) at callint.c:784
#39 0x000055555570fa9b in Ffuncall (nargs=4, args=args@entry=0x7fffffffd448) at lisp.h:2081
#40 0x000055555574cb54 in exec_byte_code (bytestr=<optimized out>, vector=<optimized out>, maxdepth=<optimized out>, args_template=<optimized out>, nargs=<optimized out>, args=<optimized out>) at bytecode.c:632
#41 0x000055555570f9d7 in Ffuncall (nargs=5, args=0x7fffffffd7b0) at eval.c:2893
#42 0x000055555570fc9d in call4 (fn=fn@entry=XIL(0x43b0), arg1=arg1@entry=XIL(0x2aaa9c29dce0), arg2=arg2@entry=XIL(0), arg3=<optimized out>, arg4=arg4@entry=XIL(0x30)) at eval.c:2761
#43 0x000055555569c0a0 in read_char (commandflag=1, map=XIL(0x5555585fc1b3), prev_event=XIL(0), used_mouse_menu=0x7fffffffddfb, end_time=0x0) at lisp.h:1007
#44 0x000055555569e224 in read_key_sequence (keybuf=<optimized out>, prompt=XIL(0), dont_downcase_last=<optimized out>, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=<optimized out>) at keyboard.c:9483
#45 0x000055555569fbbc in command_loop_1 () at lisp.h:1007
#46 0x000055555570eba7 in internal_condition_case (bfun=bfun@entry=0x55555569f9c0 <command_loop_1>, handlers=handlers@entry=XIL(0x90), hfun=hfun@entry=0x555555696310 <cmd_error>) at eval.c:1415
#47 0x00005555556907c4 in command_loop_2 (ignore=ignore@entry=XIL(0)) at lisp.h:1007
#48 0x000055555570eae9 in internal_catch (tag=tag@entry=XIL(0xd7d0), func=func@entry=0x5555556907a0 <command_loop_2>, arg=arg@entry=XIL(0)) at eval.c:1176
#49 0x0000555555690763 in command_loop () at lisp.h:1007
#50 0x0000555555695f1a in recursive_edit_1 () at keyboard.c:720
#51 0x0000555555696256 in Frecursive_edit () at keyboard.c:789
#52 0x00005555555a6a39 in main (argc=1, argv=<optimized out>) at emacs.c:2054

Lisp Backtrace:
"command-error-default-function" (0xffffc058)
"apply" (0xffffc168)
0xf22de0f8 PVEC_COMPILED
"recursive-edit" (0xffffc708)
"debug" (0xffffcbb8)
"dbus-handle-event" (0xffffd220)
"funcall-interactively" (0xffffd218)
"call-interactively" (0xffffd450)
"command-execute" (0xffffd7b8)

These crashes occur only in optimized builds.
I tried to print DBUS events in dbus-handle-event
to stdout, so in case of the crash, at least stdout
might show the cause of the problem, but can't find
a Lisp function that prints to stdout.  I tried
to add in dbus-handle-event:

  (let ((noninteractive t)) (message "DBUS: %S" event))

but it doesn't print to stdout.