mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
ash: fix prompt expansion (Natanael Copa <natanael.copa@gmail.com>)
This commit is contained in:
parent
818322b9b1
commit
46a530626d
19
shell/ash.c
19
shell/ash.c
@ -2494,6 +2494,7 @@ pwdcmd(int argc, char **argv)
|
|||||||
#define DQSYNTAX 1 /* in double quotes */
|
#define DQSYNTAX 1 /* in double quotes */
|
||||||
#define SQSYNTAX 2 /* in single quotes */
|
#define SQSYNTAX 2 /* in single quotes */
|
||||||
#define ARISYNTAX 3 /* in arithmetic */
|
#define ARISYNTAX 3 /* in arithmetic */
|
||||||
|
#define PSSYNTAX 4 /* prompt */
|
||||||
|
|
||||||
#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
|
#if ENABLE_ASH_OPTIMIZE_FOR_SIZE
|
||||||
#define USE_SIT_FUNCTION
|
#define USE_SIT_FUNCTION
|
||||||
@ -9886,6 +9887,9 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
|
|||||||
smallint dblquote;
|
smallint dblquote;
|
||||||
smallint oldstyle;
|
smallint oldstyle;
|
||||||
smallint prevsyntax; /* syntax before arithmetic */
|
smallint prevsyntax; /* syntax before arithmetic */
|
||||||
|
#if ENABLE_ASH_EXPAND_PRMT
|
||||||
|
smallint pssyntax; /* we are expanding a prompt string */
|
||||||
|
#endif
|
||||||
int varnest; /* levels of variables expansion */
|
int varnest; /* levels of variables expansion */
|
||||||
int arinest; /* levels of arithmetic expansion */
|
int arinest; /* levels of arithmetic expansion */
|
||||||
int parenlevel; /* levels of parens in arithmetic */
|
int parenlevel; /* levels of parens in arithmetic */
|
||||||
@ -9907,9 +9911,14 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
|
|||||||
startlinno = plinno;
|
startlinno = plinno;
|
||||||
bqlist = NULL;
|
bqlist = NULL;
|
||||||
quotef = 0;
|
quotef = 0;
|
||||||
dblquote = (syntax == DQSYNTAX);
|
|
||||||
oldstyle = 0;
|
oldstyle = 0;
|
||||||
prevsyntax = 0;
|
prevsyntax = 0;
|
||||||
|
#if ENABLE_ASH_EXPAND_PRMT
|
||||||
|
pssyntax = (syntax == PSSYNTAX);
|
||||||
|
if (pssyntax)
|
||||||
|
syntax = DQSYNTAX;
|
||||||
|
#endif
|
||||||
|
dblquote = (syntax == DQSYNTAX);
|
||||||
varnest = 0;
|
varnest = 0;
|
||||||
arinest = 0;
|
arinest = 0;
|
||||||
parenlevel = 0;
|
parenlevel = 0;
|
||||||
@ -9948,6 +9957,12 @@ readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
|
|||||||
if (doprompt)
|
if (doprompt)
|
||||||
setprompt(2);
|
setprompt(2);
|
||||||
} else {
|
} else {
|
||||||
|
#if ENABLE_ASH_EXPAND_PRMT
|
||||||
|
if (c == '$' && pssyntax) {
|
||||||
|
USTPUTC(CTLESC, out);
|
||||||
|
USTPUTC('\\', out);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (dblquote &&
|
if (dblquote &&
|
||||||
c != '\\' && c != '`' &&
|
c != '\\' && c != '`' &&
|
||||||
c != '$' && (
|
c != '$' && (
|
||||||
@ -10780,7 +10795,7 @@ expandstr(const char *ps)
|
|||||||
|
|
||||||
/* XXX Fix (char *) cast. */
|
/* XXX Fix (char *) cast. */
|
||||||
setinputstring((char *)ps);
|
setinputstring((char *)ps);
|
||||||
readtoken1(pgetc(), DQSYNTAX, nullstr, 0);
|
readtoken1(pgetc(), PSSYNTAX, nullstr, 0);
|
||||||
popfile();
|
popfile();
|
||||||
|
|
||||||
n.narg.type = NARG;
|
n.narg.type = NARG;
|
||||||
|
Loading…
Reference in New Issue
Block a user