From 2682149a379ed872631b9a7cfbbe5b6142775b8b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 1 Oct 2015 19:37:14 +0100 Subject: ash: preserve environment variables with invalid characters When replacing invalid characters in shell variable names use a copy of the environment variable. This leaves the original variable in the environment so that it can be seen by Windows-native child processes. --- shell/ash.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 80846da0f..e9850f493 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13471,16 +13471,10 @@ init(void) if (!(end=strchr(*envp, '='))) continue; - for (start = *envp;start < end;start++) { - /* make all variable names uppercase */ + /* make all variable names uppercase */ + for (start = *envp;start < end;start++) *start = toupper(*start); - /* replace invalid characters with underscores */ - if (!isdigit(*start) && !isalpha(*start) && *start != '_') { - *start = '_'; - } - } - /* skip conversion of variables known to cause problems */ if ( strncmp(*envp, "SYSTEMROOT=", 11) == 0 || strncmp(*envp, "COMSPEC=", 8) == 0 ) { @@ -13495,6 +13489,28 @@ init(void) } } } + + /* check for invalid characters */ + for (start = *envp;start < end;start++) { + if (!isdigit(*start) && !isalpha(*start) && *start != '_') { + break; + } + } + + if (start != end) { + /* + * Make a copy of the variable, replacing invalid + * characters in the name with underscores. + */ + char *var = xstrdup(*envp); + + for (start = var;*start != '=';start++) { + if (!isdigit(*start) && !isalpha(*start)) { + *start = '_'; + } + } + setvareq(var, VEXPORT|VNOSAVE); + } } /* some initialisation normally performed at login */ -- cgit v1.2.3-55-g6feb