Subject: bug#18140: [PATCH] macros.c: CHECK_VECTOR_OR_STRING invokes wrong_type_argument for Qnil instead of return 0

From: Andreas Schwab <[email-masked]>
Date: Tue, 29 Jul 2014 09:52:34 +0200

Jan Chaloupka <[email-masked]> writes:

> Changelog:
> 	line wrapping to 80 characters
>
> In function Fstart_kbd_macro (macros.c), Vlast_kbd_macro of current_kboard is
> Qnil for the first invocation. If NILP (append) is false,
> current_kboard->kbd_macro_ptr has random value (in our case
> 0x5353535353535353), which after CHECK_VECTOR_OR_STRING failure (invocation
> of wrong_type_argument) results in garbage collecting.
> During gc, marking of objects is processed and mark_kboards (keyboard.c) is
> invoked. Following for loop is fired:
>
> for (p = kb->kbd_macro_buffer; p < kb->kbd_macro_ptr; p++)
>                   mark_object (*p);
>
> Since kb->kbd_macro_ptr is set to 0x5353535353535353, mark_object (*p) is
> trying to mark object on address out of memory space (or memory that
> cannot be accessed). Thus resulting in SIGSEGV signal.

So the correct solution is to initialize kbd_macro_ptr together with
kbd_macro_buffer.  Otherwise the same situation can still happen any
time garbage collection is called.

Andreas.

-- 
Andreas Schwab, SUSE Labs, [email-masked]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."