Subject: bug#28279: 25.2; repeatable crash when hitting C-g twice

From: Eli Zaretskii <[email-masked]>
Date: Wed, 30 Aug 2017 19:46:36 +0300

> From: Glenn Morris <[email-masked]>
> Date: Tue, 29 Aug 2017 15:38:44 -0400
> Cc: [email-masked]
> 
> Eric Hoffman wrote:
> 
> >   0x4ad7a3 <emacs_abort+0x13> at  /usr/home/yuri/emacs-25.2/src/emacs-25.2.1
> >   0x50c474 <Fsignal+0x4b4> at /usr/home/yuri/emacs-25.2/src/emacs-25.2.1
> >   0x512cf5 <Fassq+0x15> at /usr/home/yuri/emacs-25.2/src/emacs-25.2.1
> >   0x48cfbe <Fterminal_parameter+0x7e> at  /usr/home/yuri/emacs-25.2/src/emacs-25.2.1
> >   0x48c1e7 <tty_send_additional_strings+0x17> at  /usr/home/yuri/emacs-25.2/src/emacs-25.2.1
> 
> This appears to be https://debbugs.gnu.org/17406

Does the below look reasonable for a fix?

diff --git a/src/term.c b/src/term.c
index 87a4126..5042abf 100644
--- a/src/term.c
+++ b/src/term.c
@@ -156,13 +156,17 @@ static void
 tty_send_additional_strings (struct terminal *terminal, Lisp_Object sym)
 {
   Lisp_Object lisp_terminal;
-  Lisp_Object extra_codes;
   struct tty_display_info *tty = terminal->display_info.tty;
 
   XSETTERMINAL (lisp_terminal, terminal);
-  for (extra_codes = Fterminal_parameter (lisp_terminal, sym);
-       CONSP (extra_codes);
-       extra_codes = XCDR (extra_codes))
+  /* We use CDR_SAFE and assq_no_quit to avoid any form of quitting or
+     signaling an error, since this function can run as part of the
+     "emergency escape" procedure invoked in the middle of GC, where
+     quitting means we crash.  */
+  Lisp_Object extra_codes =
+    CDR_SAFE (assq_no_quit (sym,
+			    decode_live_terminal (lisp_terminal)->param_alist));
+  for ( ; CONSP (extra_codes); extra_codes = XCDR (extra_codes))
     {
       Lisp_Object string = XCAR (extra_codes);
       if (STRINGP (string))