gcc.c (getenv_spec_function): Escape the environment variable's value.
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 1 Nov 2007 16:42:39 +0000 (16:42 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 1 Nov 2007 16:42:39 +0000 (16:42 +0000)
* gcc.c (getenv_spec_function): Escape the environment variable's
value.

From-SVN: r129825

gcc/ChangeLog
gcc/gcc.c

index 829201beb218d417d53a0ed2cdb6eac05e66863c..e87bbf21d19b50e4be0f5708242a41cd9fb687c3 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-01  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * gcc.c (getenv_spec_function): Escape the environment variable's
+       value.
+
 2007-11-01  Janis Johnson  <janis187@us.ibm.com>
 
        * doc/invoke.texi (Optimize Options): Under -fcse-follow-jumps,
index fbbee556064621e5d376cd2ebdbc410c1b0f556d..bd266496ac791dbbbd987f5d837a36174f2aa651 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -7734,6 +7734,9 @@ static const char *
 getenv_spec_function (int argc, const char **argv)
 {
   char *value;
+  char *result;
+  char *ptr;
+  size_t len;
 
   if (argc != 2)
     return NULL;
@@ -7742,7 +7745,21 @@ getenv_spec_function (int argc, const char **argv)
   if (!value)
     fatal ("environment variable \"%s\" not defined", argv[0]);
 
-  return concat (value, argv[1], NULL);
+  /* We have to escape every character of the environment variable so
+     they are not interpretted as active spec characters.  A
+     particulaly painful case is when we are reading a variable
+     holding a windows path complete with \ separators.  */
+  len = strlen (value) * 2 + strlen (argv[1]) + 1;
+  result = xmalloc (len);
+  for (ptr = result; *value; ptr += 2)
+    {
+      ptr[0] = '\\';
+      ptr[1] = *value++;
+    }
+  
+  strcpy (ptr, argv[1]);
+  
+  return result;
 }
 
 /* if-exists built-in spec function.