aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-27 11:28:59 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-27 11:28:59 +0200
commit2eb0a7e1b9a579ba34e4780c9ed8e74f38bc6b85 (patch)
treed02a7697eafd348e66aa1ef17fc5334d7b8f950e
parent70392331a98d266af539be4b910812fc7b0a72d4 (diff)
downloadbusybox-w32-2eb0a7e1b9a579ba34e4780c9ed8e74f38bc6b85.tar.gz
busybox-w32-2eb0a7e1b9a579ba34e4780c9ed8e74f38bc6b85.tar.bz2
busybox-w32-2eb0a7e1b9a579ba34e4780c9ed8e74f38bc6b85.zip
ash: [SHELL] Expand ENV before using it
Upstream commit: Date: Sun, 13 Jul 2008 21:51:52 +0800 [SHELL] Expand ENV before using it Per POSIX ENV needs to undergo parameter expansion. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c17
-rw-r--r--shell/hush.c1
2 files changed, 8 insertions, 10 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 864b8f0a4..0dd440c61 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13277,11 +13277,12 @@ procargs(char **argv)
13277} 13277}
13278 13278
13279/* 13279/*
13280 * Read /etc/profile or .profile. 13280 * Read /etc/profile, ~/.profile, $ENV.
13281 */ 13281 */
13282static void 13282static void
13283read_profile(const char *name) 13283read_profile(const char *name)
13284{ 13284{
13285 name = expandstr(name);
13285 if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) 13286 if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0)
13286 return; 13287 return;
13287 cmdloop(0); 13288 cmdloop(0);
@@ -13325,7 +13326,6 @@ extern int etext();
13325int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 13326int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
13326int ash_main(int argc UNUSED_PARAM, char **argv) 13327int ash_main(int argc UNUSED_PARAM, char **argv)
13327{ 13328{
13328 const char *shinit;
13329 volatile smallint state; 13329 volatile smallint state;
13330 struct jmploc jmploc; 13330 struct jmploc jmploc;
13331 struct stackmark smark; 13331 struct stackmark smark;
@@ -13394,11 +13394,8 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13394 state1: 13394 state1:
13395 state = 2; 13395 state = 2;
13396 hp = lookupvar("HOME"); 13396 hp = lookupvar("HOME");
13397 if (hp) { 13397 if (hp)
13398 hp = concat_path_file(hp, ".profile"); 13398 read_profile("$HOME/.profile");
13399 read_profile(hp);
13400 free((char*)hp);
13401 }
13402 } 13399 }
13403 state2: 13400 state2:
13404 state = 3; 13401 state = 3;
@@ -13408,11 +13405,11 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
13408#endif 13405#endif
13409 iflag 13406 iflag
13410 ) { 13407 ) {
13411 shinit = lookupvar("ENV"); 13408 const char *shinit = lookupvar("ENV");
13412 if (shinit != NULL && *shinit != '\0') { 13409 if (shinit != NULL && *shinit != '\0')
13413 read_profile(shinit); 13410 read_profile(shinit);
13414 }
13415 } 13411 }
13412 popstackmark(&smark);
13416 state3: 13413 state3:
13417 state = 4; 13414 state = 4;
13418 if (minusc) { 13415 if (minusc) {
diff --git a/shell/hush.c b/shell/hush.c
index d7a0d761e..c80429d5c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8405,6 +8405,7 @@ int hush_main(int argc, char **argv)
8405 * "bash <script>" (which is never interactive (unless -i?)) 8405 * "bash <script>" (which is never interactive (unless -i?))
8406 * sources $BASH_ENV here (without scanning $PATH). 8406 * sources $BASH_ENV here (without scanning $PATH).
8407 * If called as sh, does the same but with $ENV. 8407 * If called as sh, does the same but with $ENV.
8408 * Also NB, per POSIX, $ENV should undergo parameter expansion.
8408 */ 8409 */
8409 G.global_argc--; 8410 G.global_argc--;
8410 G.global_argv++; 8411 G.global_argv++;