aboutsummaryrefslogtreecommitdiffstats
path: root/src/keymap.c
diff options
context:
space:
mode:
authorPaul Eggert2011-08-29 08:43:34 -0700
committerPaul Eggert2011-08-29 08:43:34 -0700
commit62f19c197d32e8773a284616d575686d87903b7d (patch)
tree237de2d21e8a33f6821248890c01de7d83dbcba4 /src/keymap.c
parent005d87bd2306e943a16b86c36d1482651d9932d8 (diff)
downloademacs-62f19c197d32e8773a284616d575686d87903b7d.tar.gz
emacs-62f19c197d32e8773a284616d575686d87903b7d.zip
sprintf-related integer and memory overflow issues.
* doprnt.c (doprnt): Support printing ptrdiff_t and intmax_t values. (esprintf, esnprintf, exprintf, evxprintf): New functions. * keyboard.c (command_loop_level): Now EMACS_INT, not int. (cmd_error): kbd macro iterations count is now EMACS_INT, not int. (modify_event_symbol): Do not assume that the length of name_alist_or_stem is safe to alloca and fits in int. (Fexecute_extended_command): Likewise for function name and binding. (Frecursion_depth): Wrap around reliably on integer overflow. * keymap.c (push_key_description): First arg is now EMACS_INT, not int, since some callers pass EMACS_INT values. (Fsingle_key_description): Don't crash if symbol name contains more than MAX_ALLOCA bytes. * minibuf.c (minibuf_level): Now EMACS_INT, not int. (get_minibuffer): Arg is now EMACS_INT, not int. * lisp.h (get_minibuffer, push_key_description): Reflect API changes. (esprintf, esnprintf, exprintf, evxprintf): New decls. * window.h (command_loop_level, minibuf_level): Reflect API changes.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 32b531daac4..4485080db21 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2143,12 +2143,12 @@ spaces are put between sequence elements, etc. */)
2143 2143
2144 2144
2145char * 2145char *
2146push_key_description (register unsigned int c, register char *p, int force_multibyte) 2146push_key_description (EMACS_INT ch, char *p, int force_multibyte)
2147{ 2147{
2148 unsigned c2; 2148 int c, c2;
2149 2149
2150 /* Clear all the meaningless bits above the meta bit. */ 2150 /* Clear all the meaningless bits above the meta bit. */
2151 c &= meta_modifier | ~ - meta_modifier; 2151 c = ch & (meta_modifier | ~ - meta_modifier);
2152 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier 2152 c2 = c & ~(alt_modifier | ctrl_modifier | hyper_modifier
2153 | meta_modifier | shift_modifier | super_modifier); 2153 | meta_modifier | shift_modifier | super_modifier);
2154 2154
@@ -2283,10 +2283,15 @@ around function keys and event symbols. */)
2283 { 2283 {
2284 if (NILP (no_angles)) 2284 if (NILP (no_angles))
2285 { 2285 {
2286 char *buffer 2286 char *buffer;
2287 = (char *) alloca (SBYTES (SYMBOL_NAME (key)) + 5); 2287 Lisp_Object result;
2288 sprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key))); 2288 USE_SAFE_ALLOCA;
2289 return build_string (buffer); 2289 SAFE_ALLOCA (buffer, char *,
2290 sizeof "<>" + SBYTES (SYMBOL_NAME (key)));
2291 esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
2292 result = build_string (buffer);
2293 SAFE_FREE ();
2294 return result;
2290 } 2295 }
2291 else 2296 else
2292 return Fsymbol_name (key); 2297 return Fsymbol_name (key);