]> git.eshelyaron.com Git - emacs.git/commitdiff
* character.c (Fstring, Funibyte_string): Use SAFE_ALLOCA to
authorChong Yidong <cyd@stupidchicken.com>
Tue, 18 May 2010 18:01:10 +0000 (14:01 -0400)
committerChong Yidong <cyd@stupidchicken.com>
Tue, 18 May 2010 18:01:10 +0000 (14:01 -0400)
prevent stack overflow if number of arguments is too large
(Bug#6214).

src/ChangeLog
src/character.c

index 8e2774f2a034b568ac45587a1b741e63b596f3a1..557cda8d4f94307f6a4e715ac674d253a271f5c4 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-18  Chong Yidong  <cyd@stupidchicken.com>
+
+       * character.c (Fstring, Funibyte_string): Use SAFE_ALLOCA to
+       prevent stack overflow if number of arguments is too large
+       (Bug#6214).
+
 2010-05-11  Eli Zaretskii  <eliz@gnu.org>
 
        * makefile.w32-in ($(BLD)/w32fns.$(O)): Depend on $(SRC)/w32.h.
index 5912a70d0ce82f47815d151e6e481d92aa0deaa1..7cd1eedcef4ae8b79bb5042cff5430853298af0c 100644 (file)
@@ -961,10 +961,13 @@ usage: (string &rest CHARACTERS)  */)
      int n;
      Lisp_Object *args;
 {
-  int i;
-  unsigned char *buf = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH * n);
-  unsigned char *p = buf;
-  int c;
+  int i, c;
+  unsigned char *buf, *p;
+  Lisp_Object str;
+  USE_SAFE_ALLOCA;
+
+  SAFE_ALLOCA (buf, unsigned char *, MAX_MULTIBYTE_LENGTH * n);
+  p = buf;
 
   for (i = 0; i < n; i++)
     {
@@ -973,7 +976,9 @@ usage: (string &rest CHARACTERS)  */)
       p += CHAR_STRING (c, p);
     }
 
-  return make_string_from_bytes ((char *) buf, n, p - buf);
+  str = make_string_from_bytes ((char *) buf, n, p - buf);
+  SAFE_FREE ();
+  return str;
 }
 
 DEFUN ("unibyte-string", Funibyte_string, Sunibyte_string, 0, MANY, 0,
@@ -983,10 +988,13 @@ usage: (unibyte-string &rest BYTES)  */)
      int n;
      Lisp_Object *args;
 {
-  int i;
-  unsigned char *buf = (unsigned char *) alloca (n);
-  unsigned char *p = buf;
-  unsigned c;
+  int i, c;
+  unsigned char *buf, *p;
+  Lisp_Object str;
+  USE_SAFE_ALLOCA;
+
+  SAFE_ALLOCA (buf, unsigned char *, n);
+  p = buf;
 
   for (i = 0; i < n; i++)
     {
@@ -997,7 +1005,9 @@ usage: (unibyte-string &rest BYTES)  */)
       *p++ = c;
     }
 
-  return make_string_from_bytes ((char *) buf, n, p - buf);
+  str = make_string_from_bytes ((char *) buf, n, p - buf);
+  SAFE_FREE ();
+  return str;
 }
 
 DEFUN ("char-resolve-modifiers", Fchar_resolve_modifiers,