emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r101541: src/w32.c (get_emacs_configu


From: Juanma Barranquero
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101541: src/w32.c (get_emacs_configuration_options): Fix buffer overrun.
Date: Wed, 22 Sep 2010 19:31:21 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101541
committer: Juanma Barranquero <address@hidden>
branch nick: trunk
timestamp: Wed 2010-09-22 19:31:21 +0200
message:
  src/w32.c (get_emacs_configuration_options): Fix buffer overrun.
modified:
  src/ChangeLog
  src/w32.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2010-09-22 16:03:34 +0000
+++ b/src/ChangeLog     2010-09-22 17:31:21 +0000
@@ -1,3 +1,8 @@
+2010-09-22  Juanma Barranquero  <address@hidden>
+            Eli Zaretskii  <address@hidden>
+
+       * w32.c (get_emacs_configuration_options): Fix buffer overrun.
+
 2010-09-22  Eli Zaretskii  <address@hidden>
 
        * minibuf.c (Fminibuffer_contents)

=== modified file 'src/w32.c'
--- a/src/w32.c 2010-09-20 00:18:18 +0000
+++ b/src/w32.c 2010-09-22 17:31:21 +0000
@@ -1925,7 +1925,25 @@
 char *
 get_emacs_configuration_options (void)
 {
-  static char options_buffer[256];
+  static char *options_buffer;
+  char cv[32];  /* Enough for COMPILER_VERSION.  */
+  char *options[] = {
+    cv,  /* To be filled later.  */
+#ifdef EMACSDEBUG
+    " --no-opt",
+#endif
+    /* configure.bat already sets USER_CFLAGS and USER_LDFLAGS
+       with a starting space to save work here.  */
+#ifdef USER_CFLAGS
+    " --cflags", USER_CFLAGS,
+#endif
+#ifdef USER_LDFLAGS
+    " --ldflags", USER_LDFLAGS,
+#endif
+    NULL
+  };
+  size_t size = 0;
+  int i;
 
 /* Work out the effective configure options for this build.  */
 #ifdef _MSC_VER
@@ -1938,18 +1956,17 @@
 #endif
 #endif
 
-  sprintf (options_buffer, COMPILER_VERSION);
-#ifdef EMACSDEBUG
-  strcat (options_buffer, " --no-opt");
-#endif
-#ifdef USER_CFLAGS
-  strcat (options_buffer, " --cflags");
-  strcat (options_buffer, USER_CFLAGS);
-#endif
-#ifdef USER_LDFLAGS
-  strcat (options_buffer, " --ldflags");
-  strcat (options_buffer, USER_LDFLAGS);
-#endif
+  if (_snprintf (cv, sizeof (cv), COMPILER_VERSION) < 0)
+    return "Error: not enough space for compiler version";
+
+  for (i = 0; options[i]; i++)
+    size += strlen (options[i]);
+
+  options_buffer = xmalloc (size + 1);
+
+  for (i = 0; options[i]; i++)
+    strcat (options_buffer, options[i]);
+
   return options_buffer;
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]