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

From: Juri Linkov <[email-masked]>
Date: Mon, 28 Dec 2020 19:03:47 +0200

retitle 45277 Non-DBus crashes
quit

>>> Do you have a recipe how to provoke this error?
>>
>> After dbus-handle-event started to pull random parts of the init file
>> to use as its event arg, I realized that something is wrong with the build,
>> made clean bootstrap, and D-Bus problems went away.  Sorry for false alarm.
>
> No problem, I'm happy there's no random bug in dbusbind.c.

Bad news: after pull from master and recompiling it crashes again.

Good news: crashes are not caused by dbusbind.c.

Usually, DBUS_DEBUG prints such lines:

  xd_read_message_1: Event received: ...
  xd_read_message_1: Event stored: ...
  xd_read_message_1: Event received: ...
  xd_read_message_1: Event stored: ...
  ...

But when such error is signaled:

  Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p "Click to close tab")
    dbus-handle-event((dbus-event :help "Click to close tab"))
    funcall-interactively(dbus-handle-event (dbus-event :help "Click to close tab"))
    call-interactively(dbus-handle-event nil [(dbus-event :help "Click to close tab")])
    command-execute(dbus-handle-event nil [(dbus-event :help "Click to close tab")] t)

there were no DBUS_DEBUG messages before this error comes.
So the erroneous events are not added by dbusbind.c.

Here's is a brief sequence of events:

1. In web browser copied a URL to the clipboard;
2. In Emacs this immediately causes a DBUS_EVENT event added to kbd_buffer:

Thread 1 "emacs" hit Breakpoint 5, make_lispy_event (event=0x555555cb93c8 <kbd_buffer+100520>) at keyboard.c:6015
6015		return Fcons (Qdbus_event, event->arg);

(gdb) bt
#0  make_lispy_event (event=0x555555cb93c8 <kbd_buffer+100520>) at keyboard.c:6015
#1  0x00005555557131b9 in kbd_buffer_get_event (kbp=0x7fffffffc668, used_mouse_menu=0x7fffffffdcb9, end_time=0x0) at keyboard.c:3978
#2  0x000055555570ed06 in read_event_from_main_queue (end_time=0x0, local_getcjmp=0x7fffffffcab0, used_mouse_menu=0x7fffffffdcb9) at keyboard.c:2159
#3  0x000055555570f023 in read_decoded_event_from_main_queue (end_time=0x0, local_getcjmp=0x7fffffffcab0, prev_event=XIL(0), used_mouse_menu=0x7fffffffdcb9) at keyboard.c:2223
#4  0x0000555555710857 in read_char (commandflag=1, map=XIL(0x55555a5c9943), prev_event=XIL(0), used_mouse_menu=0x7fffffffdcb9, end_time=0x0) at keyboard.c:2833
#5  0x000055555571fab7 in read_key_sequence (keybuf=0x7fffffffdee0, prompt=XIL(0), dont_downcase_last=false, can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:9498
#6  0x000055555570c918 in command_loop_1 () at keyboard.c:1353
#7  0x00005555557caed4 in internal_condition_case (bfun=0x55555570c4b0 <command_loop_1>, handlers=XIL(0x90), hfun=0x55555570bbed <cmd_error>) at eval.c:1415
#8  0x000055555570c154 in command_loop_2 (ignore=XIL(0)) at keyboard.c:1094
#9  0x00005555557ca6d7 in internal_catch (tag=XIL(0xd800), func=0x55555570c123 <command_loop_2>, arg=XIL(0)) at eval.c:1176
#10 0x000055555570c0ef in command_loop () at keyboard.c:1073
#11 0x000055555570b79e in recursive_edit_1 () at keyboard.c:720
#12 0x000055555570b929 in Frecursive_edit () at keyboard.c:789
#13 0x00005555557080a0 in main (argc=1, argv=0x7fffffffe368) at emacs.c:2054

(gdb) fr 1
#1  0x00005555557131b9 in kbd_buffer_get_event (kbp=0x7fffffffc668, used_mouse_menu=0x7fffffffdcb9, end_time=0x0) at keyboard.c:3978
3978	          obj = make_lispy_event (&event->ie);

(gdb) p event->kind
$1 = DBUS_EVENT

(gdb) p (int)event->kind
$2 = 27

(gdb) p event->ie
$3 = {
  kind = DBUS_EVENT,
  part = scroll_bar_nowhere,
  code = 0,
  modifiers = 0,
  x = XIL(0),
  y = XIL(0),
  timestamp = 0,
  frame_or_window = XIL(0),
  arg = XIL(0x555557db7e23)
}

(gdb) p event->ie->arg
$4 = XIL(0x555557db7e23)

(gdb) pr
(:help "Click to close tab")

(gdb) p event->sie
$5 = {
  kind = DBUS_EVENT,
  dpyinfo = 0x0,
  requestor = 0,
  selection = 0,
  target = 0,
  property = 0,
  time = 0
}

(gdb) c
Continuing.

Thread 1 "emacs" hit Breakpoint 5, make_lispy_event (event=0x555555cbd0d0 <kbd_buffer+116144>) at keyboard.c:6015
6015		return Fcons (Qdbus_event, event->arg);

(gdb) fr 1
#1  0x00005555557131b9 in kbd_buffer_get_event (kbp=0x7fffffffc668, used_mouse_menu=0x7fffffffdcb9, end_time=0x0) at keyboard.c:3978
3978	          obj = make_lispy_event (&event->ie);

(gdb) p event->kind
$6 = DBUS_EVENT

(gdb) p event->ie
$7 = {
  kind = DBUS_EVENT,
  part = scroll_bar_nowhere,
  code = 0,
  modifiers = 0,
  x = XIL(0),
  y = XIL(0),
  timestamp = 0,
  frame_or_window = XIL(0),
  arg = XIL(0x555560a70f43)
}

(gdb) p event->ie->arg
$8 = XIL(0x555560a70f43)

(gdb) pr
#<INVALID_LISP_OBJECT 0x555560a70f43>

(gdb) c
Continuing.

Thread 1 "emacs" received signal SIGSEGV, Segmentation fault.
string_intervals (s=XIL(0x6c613a5b5e5b285c)) at lisp.h:3404
3404	  return XSTRING (s)->u.s.intervals;

Maybe making bootstrap after every pull from master will solve these problems?