aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-10-01 19:37:14 +0100
committerRon Yorston <rmy@pobox.com>2015-10-01 19:37:14 +0100
commit2682149a379ed872631b9a7cfbbe5b6142775b8b (patch)
tree591144e672f6b417914cd8cbc952a7dab18d26b9
parentff5ef2920fd216e4c2f8f17cfd64f46cc9adc60c (diff)
downloadbusybox-w32-2682149a379ed872631b9a7cfbbe5b6142775b8b.tar.gz
busybox-w32-2682149a379ed872631b9a7cfbbe5b6142775b8b.tar.bz2
busybox-w32-2682149a379ed872631b9a7cfbbe5b6142775b8b.zip
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.
-rw-r--r--shell/ash.c32
1 files 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)
13471 if (!(end=strchr(*envp, '='))) 13471 if (!(end=strchr(*envp, '=')))
13472 continue; 13472 continue;
13473 13473
13474 for (start = *envp;start < end;start++) { 13474 /* make all variable names uppercase */
13475 /* make all variable names uppercase */ 13475 for (start = *envp;start < end;start++)
13476 *start = toupper(*start); 13476 *start = toupper(*start);
13477 13477
13478 /* replace invalid characters with underscores */
13479 if (!isdigit(*start) && !isalpha(*start) && *start != '_') {
13480 *start = '_';
13481 }
13482 }
13483
13484 /* skip conversion of variables known to cause problems */ 13478 /* skip conversion of variables known to cause problems */
13485 if ( strncmp(*envp, "SYSTEMROOT=", 11) == 0 || 13479 if ( strncmp(*envp, "SYSTEMROOT=", 11) == 0 ||
13486 strncmp(*envp, "COMSPEC=", 8) == 0 ) { 13480 strncmp(*envp, "COMSPEC=", 8) == 0 ) {
@@ -13495,6 +13489,28 @@ init(void)
13495 } 13489 }
13496 } 13490 }
13497 } 13491 }
13492
13493 /* check for invalid characters */
13494 for (start = *envp;start < end;start++) {
13495 if (!isdigit(*start) && !isalpha(*start) && *start != '_') {
13496 break;
13497 }
13498 }
13499
13500 if (start != end) {
13501 /*
13502 * Make a copy of the variable, replacing invalid
13503 * characters in the name with underscores.
13504 */
13505 char *var = xstrdup(*envp);
13506
13507 for (start = var;*start != '=';start++) {
13508 if (!isdigit(*start) && !isalpha(*start)) {
13509 *start = '_';
13510 }
13511 }
13512 setvareq(var, VEXPORT|VNOSAVE);
13513 }
13498 } 13514 }
13499 13515
13500 /* some initialisation normally performed at login */ 13516 /* some initialisation normally performed at login */