diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2007-11-01 16:42:39 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2007-11-01 16:42:39 +0000 |
commit | 5557813a4e6e7f86b90a64112ad51da79827e512 (patch) | |
tree | a87db7af0cc74dd35134e4a4bff638f3af1d4a1e /gcc/gcc.c | |
parent | d6a64b9df961ae0e885a50a6b01fb2b846e60f12 (diff) | |
download | gcc-5557813a4e6e7f86b90a64112ad51da79827e512.zip gcc-5557813a4e6e7f86b90a64112ad51da79827e512.tar.gz gcc-5557813a4e6e7f86b90a64112ad51da79827e512.tar.bz2 |
gcc.c (getenv_spec_function): Escape the environment variable's value.
* gcc.c (getenv_spec_function): Escape the environment variable's
value.
From-SVN: r129825
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r-- | gcc/gcc.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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. |