diff options
| author | Eli Zaretskii | 2019-02-13 17:39:31 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2019-02-13 17:43:55 +0200 |
| commit | 6d89120b156576ca24e03472563f5ea0f01313f8 (patch) | |
| tree | 89cef46e498e3a510eac9a9324c3f69d9951fbdf /src | |
| parent | 3f4b8e9a299f88a8ea11c0ea6a281a34852e541a (diff) | |
| download | emacs-6d89120b156576ca24e03472563f5ea0f01313f8.tar.gz emacs-6d89120b156576ca24e03472563f5ea0f01313f8.zip | |
Avoid crashes upon C-g in nested invocations of 'read_char'
* src/keyboard.c (read_char, read_event_from_main_queue):
Ensure the global value of getcjmp is restored when the stack
is unwound by the likes of 'throw', by calling
record_unwind_protect_ptr instead of restoring the value
manually. (Bug#34394)
(restore_getcjmp): Argument is now 'void *', to match the
signature of record_unwind_protect_ptr.
(cherry picked from commit 10527fca66e39d7067986904161fa33741abcd26)
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 49c687f69a8..282eac72b92 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -364,7 +364,7 @@ static Lisp_Object make_lispy_focus_out (Lisp_Object); | |||
| 364 | #endif /* HAVE_WINDOW_SYSTEM */ | 364 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 365 | static bool help_char_p (Lisp_Object); | 365 | static bool help_char_p (Lisp_Object); |
| 366 | static void save_getcjmp (sys_jmp_buf); | 366 | static void save_getcjmp (sys_jmp_buf); |
| 367 | static void restore_getcjmp (sys_jmp_buf); | 367 | static void restore_getcjmp (void *); |
| 368 | static Lisp_Object apply_modifiers (int, Lisp_Object); | 368 | static Lisp_Object apply_modifiers (int, Lisp_Object); |
| 369 | static void restore_kboard_configuration (int); | 369 | static void restore_kboard_configuration (int); |
| 370 | static void handle_interrupt (bool); | 370 | static void handle_interrupt (bool); |
| @@ -2144,12 +2144,14 @@ read_event_from_main_queue (struct timespec *end_time, | |||
| 2144 | return c; | 2144 | return c; |
| 2145 | 2145 | ||
| 2146 | /* Actually read a character, waiting if necessary. */ | 2146 | /* Actually read a character, waiting if necessary. */ |
| 2147 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2147 | save_getcjmp (save_jump); | 2148 | save_getcjmp (save_jump); |
| 2149 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2148 | restore_getcjmp (local_getcjmp); | 2150 | restore_getcjmp (local_getcjmp); |
| 2149 | if (!end_time) | 2151 | if (!end_time) |
| 2150 | timer_start_idle (); | 2152 | timer_start_idle (); |
| 2151 | c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time); | 2153 | c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time); |
| 2152 | restore_getcjmp (save_jump); | 2154 | unbind_to (count, Qnil); |
| 2153 | 2155 | ||
| 2154 | if (! NILP (c) && (kb != current_kboard)) | 2156 | if (! NILP (c) && (kb != current_kboard)) |
| 2155 | { | 2157 | { |
| @@ -2638,10 +2640,12 @@ read_char (int commandflag, Lisp_Object map, | |||
| 2638 | { | 2640 | { |
| 2639 | Lisp_Object tem0; | 2641 | Lisp_Object tem0; |
| 2640 | 2642 | ||
| 2643 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2641 | save_getcjmp (save_jump); | 2644 | save_getcjmp (save_jump); |
| 2645 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2642 | restore_getcjmp (local_getcjmp); | 2646 | restore_getcjmp (local_getcjmp); |
| 2643 | tem0 = sit_for (Vecho_keystrokes, 1, 1); | 2647 | tem0 = sit_for (Vecho_keystrokes, 1, 1); |
| 2644 | restore_getcjmp (save_jump); | 2648 | unbind_to (count, Qnil); |
| 2645 | if (EQ (tem0, Qt) | 2649 | if (EQ (tem0, Qt) |
| 2646 | && ! CONSP (Vunread_command_events)) | 2650 | && ! CONSP (Vunread_command_events)) |
| 2647 | echo_now (); | 2651 | echo_now (); |
| @@ -2712,10 +2716,12 @@ read_char (int commandflag, Lisp_Object map, | |||
| 2712 | 2716 | ||
| 2713 | timeout = min (timeout, MOST_POSITIVE_FIXNUM / delay_level * 4); | 2717 | timeout = min (timeout, MOST_POSITIVE_FIXNUM / delay_level * 4); |
| 2714 | timeout = delay_level * timeout / 4; | 2718 | timeout = delay_level * timeout / 4; |
| 2719 | ptrdiff_t count1 = SPECPDL_INDEX (); | ||
| 2715 | save_getcjmp (save_jump); | 2720 | save_getcjmp (save_jump); |
| 2721 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2716 | restore_getcjmp (local_getcjmp); | 2722 | restore_getcjmp (local_getcjmp); |
| 2717 | tem0 = sit_for (make_number (timeout), 1, 1); | 2723 | tem0 = sit_for (make_number (timeout), 1, 1); |
| 2718 | restore_getcjmp (save_jump); | 2724 | unbind_to (count1, Qnil); |
| 2719 | 2725 | ||
| 2720 | if (EQ (tem0, Qt) | 2726 | if (EQ (tem0, Qt) |
| 2721 | && ! CONSP (Vunread_command_events)) | 2727 | && ! CONSP (Vunread_command_events)) |
| @@ -3325,7 +3331,7 @@ save_getcjmp (sys_jmp_buf temp) | |||
| 3325 | } | 3331 | } |
| 3326 | 3332 | ||
| 3327 | static void | 3333 | static void |
| 3328 | restore_getcjmp (sys_jmp_buf temp) | 3334 | restore_getcjmp (void *temp) |
| 3329 | { | 3335 | { |
| 3330 | memcpy (getcjmp, temp, sizeof getcjmp); | 3336 | memcpy (getcjmp, temp, sizeof getcjmp); |
| 3331 | } | 3337 | } |