diff options
| author | Eli Zaretskii | 2019-02-13 17:39:31 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2019-02-13 17:39:31 +0200 |
| commit | 10527fca66e39d7067986904161fa33741abcd26 (patch) | |
| tree | 368f966b40d81b750d70e5bf7e5f26232ac9f8b1 /src | |
| parent | ae4bfd52deecfccbbeb20ac852564b75a1bb83ff (diff) | |
| download | emacs-10527fca66e39d7067986904161fa33741abcd26.tar.gz emacs-10527fca66e39d7067986904161fa33741abcd26.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.
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 cd1747ea88c..1d67c3eaabd 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -360,7 +360,7 @@ static Lisp_Object make_lispy_focus_in (Lisp_Object); | |||
| 360 | static Lisp_Object make_lispy_focus_out (Lisp_Object); | 360 | static Lisp_Object make_lispy_focus_out (Lisp_Object); |
| 361 | static bool help_char_p (Lisp_Object); | 361 | static bool help_char_p (Lisp_Object); |
| 362 | static void save_getcjmp (sys_jmp_buf); | 362 | static void save_getcjmp (sys_jmp_buf); |
| 363 | static void restore_getcjmp (sys_jmp_buf); | 363 | static void restore_getcjmp (void *); |
| 364 | static Lisp_Object apply_modifiers (int, Lisp_Object); | 364 | static Lisp_Object apply_modifiers (int, Lisp_Object); |
| 365 | static void restore_kboard_configuration (int); | 365 | static void restore_kboard_configuration (int); |
| 366 | static void handle_interrupt (bool); | 366 | static void handle_interrupt (bool); |
| @@ -2126,12 +2126,14 @@ read_event_from_main_queue (struct timespec *end_time, | |||
| 2126 | return c; | 2126 | return c; |
| 2127 | 2127 | ||
| 2128 | /* Actually read a character, waiting if necessary. */ | 2128 | /* Actually read a character, waiting if necessary. */ |
| 2129 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2129 | save_getcjmp (save_jump); | 2130 | save_getcjmp (save_jump); |
| 2131 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2130 | restore_getcjmp (local_getcjmp); | 2132 | restore_getcjmp (local_getcjmp); |
| 2131 | if (!end_time) | 2133 | if (!end_time) |
| 2132 | timer_start_idle (); | 2134 | timer_start_idle (); |
| 2133 | c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time); | 2135 | c = kbd_buffer_get_event (&kb, used_mouse_menu, end_time); |
| 2134 | restore_getcjmp (save_jump); | 2136 | unbind_to (count, Qnil); |
| 2135 | 2137 | ||
| 2136 | if (! NILP (c) && (kb != current_kboard)) | 2138 | if (! NILP (c) && (kb != current_kboard)) |
| 2137 | { | 2139 | { |
| @@ -2620,10 +2622,12 @@ read_char (int commandflag, Lisp_Object map, | |||
| 2620 | { | 2622 | { |
| 2621 | Lisp_Object tem0; | 2623 | Lisp_Object tem0; |
| 2622 | 2624 | ||
| 2625 | ptrdiff_t count = SPECPDL_INDEX (); | ||
| 2623 | save_getcjmp (save_jump); | 2626 | save_getcjmp (save_jump); |
| 2627 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2624 | restore_getcjmp (local_getcjmp); | 2628 | restore_getcjmp (local_getcjmp); |
| 2625 | tem0 = sit_for (Vecho_keystrokes, 1, 1); | 2629 | tem0 = sit_for (Vecho_keystrokes, 1, 1); |
| 2626 | restore_getcjmp (save_jump); | 2630 | unbind_to (count, Qnil); |
| 2627 | if (EQ (tem0, Qt) | 2631 | if (EQ (tem0, Qt) |
| 2628 | && ! CONSP (Vunread_command_events)) | 2632 | && ! CONSP (Vunread_command_events)) |
| 2629 | echo_now (); | 2633 | echo_now (); |
| @@ -2694,10 +2698,12 @@ read_char (int commandflag, Lisp_Object map, | |||
| 2694 | 2698 | ||
| 2695 | timeout = min (timeout, MOST_POSITIVE_FIXNUM / delay_level * 4); | 2699 | timeout = min (timeout, MOST_POSITIVE_FIXNUM / delay_level * 4); |
| 2696 | timeout = delay_level * timeout / 4; | 2700 | timeout = delay_level * timeout / 4; |
| 2701 | ptrdiff_t count1 = SPECPDL_INDEX (); | ||
| 2697 | save_getcjmp (save_jump); | 2702 | save_getcjmp (save_jump); |
| 2703 | record_unwind_protect_ptr (restore_getcjmp, save_jump); | ||
| 2698 | restore_getcjmp (local_getcjmp); | 2704 | restore_getcjmp (local_getcjmp); |
| 2699 | tem0 = sit_for (make_fixnum (timeout), 1, 1); | 2705 | tem0 = sit_for (make_fixnum (timeout), 1, 1); |
| 2700 | restore_getcjmp (save_jump); | 2706 | unbind_to (count1, Qnil); |
| 2701 | 2707 | ||
| 2702 | if (EQ (tem0, Qt) | 2708 | if (EQ (tem0, Qt) |
| 2703 | && ! CONSP (Vunread_command_events)) | 2709 | && ! CONSP (Vunread_command_events)) |
| @@ -3320,7 +3326,7 @@ save_getcjmp (sys_jmp_buf temp) | |||
| 3320 | } | 3326 | } |
| 3321 | 3327 | ||
| 3322 | static void | 3328 | static void |
| 3323 | restore_getcjmp (sys_jmp_buf temp) | 3329 | restore_getcjmp (void *temp) |
| 3324 | { | 3330 | { |
| 3325 | memcpy (getcjmp, temp, sizeof getcjmp); | 3331 | memcpy (getcjmp, temp, sizeof getcjmp); |
| 3326 | } | 3332 | } |