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>
This commit is contained in:
Denys Vlasenko 2016-10-27 11:28:59 +02:00
parent 70392331a9
commit 2eb0a7e1b9
2 changed files with 8 additions and 10 deletions

View File

@ -13277,11 +13277,12 @@ procargs(char **argv)
} }
/* /*
* Read /etc/profile or .profile. * Read /etc/profile, ~/.profile, $ENV.
*/ */
static void static void
read_profile(const char *name) read_profile(const char *name)
{ {
name = expandstr(name);
if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0) if (setinputfile(name, INPUT_PUSH_FILE | INPUT_NOFILE_OK) < 0)
return; return;
cmdloop(0); cmdloop(0);
@ -13325,7 +13326,6 @@ extern int etext();
int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ash_main(int argc UNUSED_PARAM, char **argv) int ash_main(int argc UNUSED_PARAM, char **argv)
{ {
const char *shinit;
volatile smallint state; volatile smallint state;
struct jmploc jmploc; struct jmploc jmploc;
struct stackmark smark; struct stackmark smark;
@ -13394,11 +13394,8 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
state1: state1:
state = 2; state = 2;
hp = lookupvar("HOME"); hp = lookupvar("HOME");
if (hp) { if (hp)
hp = concat_path_file(hp, ".profile"); read_profile("$HOME/.profile");
read_profile(hp);
free((char*)hp);
}
} }
state2: state2:
state = 3; state = 3;
@ -13408,11 +13405,11 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
#endif #endif
iflag iflag
) { ) {
shinit = lookupvar("ENV"); const char *shinit = lookupvar("ENV");
if (shinit != NULL && *shinit != '\0') { if (shinit != NULL && *shinit != '\0')
read_profile(shinit); read_profile(shinit);
}
} }
popstackmark(&smark);
state3: state3:
state = 4; state = 4;
if (minusc) { if (minusc) {

View File

@ -8405,6 +8405,7 @@ int hush_main(int argc, char **argv)
* "bash <script>" (which is never interactive (unless -i?)) * "bash <script>" (which is never interactive (unless -i?))
* sources $BASH_ENV here (without scanning $PATH). * sources $BASH_ENV here (without scanning $PATH).
* If called as sh, does the same but with $ENV. * If called as sh, does the same but with $ENV.
* Also NB, per POSIX, $ENV should undergo parameter expansion.
*/ */
G.global_argc--; G.global_argc--;
G.global_argv++; G.global_argv++;