diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-24 18:30:02 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-24 18:30:02 +0000 |
commit | 46a530626d93419ea29cca73a181e3893aeea261 (patch) | |
tree | e5d59aea20c03968113a1ea129effffd7743967b | |
parent | 818322b9b19a452d66a07ca69256e2c092f5db5f (diff) | |
download | busybox-w32-46a530626d93419ea29cca73a181e3893aeea261.tar.gz busybox-w32-46a530626d93419ea29cca73a181e3893aeea261.tar.bz2 busybox-w32-46a530626d93419ea29cca73a181e3893aeea261.zip |
ash: fix prompt expansion (Natanael Copa <natanael.copa@gmail.com>)
-rw-r--r-- | shell/ash.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/shell/ash.c b/shell/ash.c index 167232c33..a3bfe3977 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2494,6 +2494,7 @@ pwdcmd(int argc, char **argv) | |||
2494 | #define DQSYNTAX 1 /* in double quotes */ | 2494 | #define DQSYNTAX 1 /* in double quotes */ |
2495 | #define SQSYNTAX 2 /* in single quotes */ | 2495 | #define SQSYNTAX 2 /* in single quotes */ |
2496 | #define ARISYNTAX 3 /* in arithmetic */ | 2496 | #define ARISYNTAX 3 /* in arithmetic */ |
2497 | #define PSSYNTAX 4 /* prompt */ | ||
2497 | 2498 | ||
2498 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE | 2499 | #if ENABLE_ASH_OPTIMIZE_FOR_SIZE |
2499 | #define USE_SIT_FUNCTION | 2500 | #define USE_SIT_FUNCTION |
@@ -9886,6 +9887,9 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) | |||
9886 | smallint dblquote; | 9887 | smallint dblquote; |
9887 | smallint oldstyle; | 9888 | smallint oldstyle; |
9888 | smallint prevsyntax; /* syntax before arithmetic */ | 9889 | smallint prevsyntax; /* syntax before arithmetic */ |
9890 | #if ENABLE_ASH_EXPAND_PRMT | ||
9891 | smallint pssyntax; /* we are expanding a prompt string */ | ||
9892 | #endif | ||
9889 | int varnest; /* levels of variables expansion */ | 9893 | int varnest; /* levels of variables expansion */ |
9890 | int arinest; /* levels of arithmetic expansion */ | 9894 | int arinest; /* levels of arithmetic expansion */ |
9891 | int parenlevel; /* levels of parens in arithmetic */ | 9895 | int parenlevel; /* levels of parens in arithmetic */ |
@@ -9907,9 +9911,14 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) | |||
9907 | startlinno = plinno; | 9911 | startlinno = plinno; |
9908 | bqlist = NULL; | 9912 | bqlist = NULL; |
9909 | quotef = 0; | 9913 | quotef = 0; |
9910 | dblquote = (syntax == DQSYNTAX); | ||
9911 | oldstyle = 0; | 9914 | oldstyle = 0; |
9912 | prevsyntax = 0; | 9915 | prevsyntax = 0; |
9916 | #if ENABLE_ASH_EXPAND_PRMT | ||
9917 | pssyntax = (syntax == PSSYNTAX); | ||
9918 | if (pssyntax) | ||
9919 | syntax = DQSYNTAX; | ||
9920 | #endif | ||
9921 | dblquote = (syntax == DQSYNTAX); | ||
9913 | varnest = 0; | 9922 | varnest = 0; |
9914 | arinest = 0; | 9923 | arinest = 0; |
9915 | parenlevel = 0; | 9924 | parenlevel = 0; |
@@ -9948,6 +9957,12 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs) | |||
9948 | if (doprompt) | 9957 | if (doprompt) |
9949 | setprompt(2); | 9958 | setprompt(2); |
9950 | } else { | 9959 | } else { |
9960 | #if ENABLE_ASH_EXPAND_PRMT | ||
9961 | if (c == '$' && pssyntax) { | ||
9962 | USTPUTC(CTLESC, out); | ||
9963 | USTPUTC('\\', out); | ||
9964 | } | ||
9965 | #endif | ||
9951 | if (dblquote && | 9966 | if (dblquote && |
9952 | c != '\\' && c != '`' && | 9967 | c != '\\' && c != '`' && |
9953 | c != '$' && ( | 9968 | c != '$' && ( |
@@ -10780,7 +10795,7 @@ expandstr(const char *ps) | |||
10780 | 10795 | ||
10781 | /* XXX Fix (char *) cast. */ | 10796 | /* XXX Fix (char *) cast. */ |
10782 | setinputstring((char *)ps); | 10797 | setinputstring((char *)ps); |
10783 | readtoken1(pgetc(), DQSYNTAX, nullstr, 0); | 10798 | readtoken1(pgetc(), PSSYNTAX, nullstr, 0); |
10784 | popfile(); | 10799 | popfile(); |
10785 | 10800 | ||
10786 | n.narg.type = NARG; | 10801 | n.narg.type = NARG; |