From ff5ef2920fd216e4c2f8f17cfd64f46cc9adc60c Mon Sep 17 00:00:00 2001 From: Ron Yorston <rmy@pobox.com> Date: Wed, 30 Sep 2015 11:17:17 +0100 Subject: ash: replace invalid characters in variable names with '_' Microsoft Windows has environment variables with names like 'ProgramFiles(x86)'. When the environment is imported into the shell replace invalid characters with underscores. --- shell/ash.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index f23a3e1ff..80846da0f 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13471,10 +13471,16 @@ init(void) if (!(end=strchr(*envp, '='))) continue; - /* make all variable names uppercase */ - for (start = *envp;start < end;start++) + for (start = *envp;start < end;start++) { + /* make all variable names uppercase */ *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 ) { -- cgit v1.2.3-55-g6feb