summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2015-09-30 14:33:41 +0000
committertedu <tedu@openbsd.org>2015-09-30 14:33:41 +0000
commit1c2ba45a796f01321642a365d5bab481556a2e55 (patch)
tree6cd874c0ca646478f0241e2b7b4073879b618459
parentFix a bug in the regress, and be much more pedantic about what is allowed (diff)
downloadwireguard-openbsd-1c2ba45a796f01321642a365d5bab481556a2e55.tar.xz
wireguard-openbsd-1c2ba45a796f01321642a365d5bab481556a2e55.zip
fix error message for csh-history. the lexer needs to back up more.
from Michael McConville
-rw-r--r--bin/ksh/lex.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c
index 8bdf471f553..ce833b7ff83 100644
--- a/bin/ksh/lex.c
+++ b/bin/ksh/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.55 2015/09/22 21:50:40 millert Exp $ */
+/* $OpenBSD: lex.c,v 1.56 2015/09/30 14:33:41 tedu Exp $ */
/*
* lexical analysis and source input
@@ -163,6 +163,9 @@ yylex(int cf)
if (Flag(FCSHHISTORY) && (source->flags & SF_TTY) &&
c == '!') {
char **replace = NULL;
+ int get, i;
+ char match[200], *str = match;
+ size_t mlen;
c2 = getsc();
if (c2 == '\0' || c2 == ' ' || c2 == '\t')
@@ -171,8 +174,7 @@ yylex(int cf)
replace = hist_get_newest(0);
else if (isdigit(c2) || c2 == '-' ||
isalpha(c2)) {
- int get = !isalpha(c2);
- char match[200], *str = match;
+ get = !isalpha(c2);
*str++ = c2;
do {
@@ -216,8 +218,12 @@ yylex(int cf)
s->u.freeme = NULL;
source = s;
continue;
- } else
- ungetsc(c2);
+ } else {
+ /* restore what followed the '!' */
+ mlen = strlen(match);
+ for (i = mlen-1; i >= 0; i--)
+ ungetsc(match[i]);
+ }
}
if (c == '[' && (cf & (VARASN|ARRAYVAR))) {
*wp = EOS; /* temporary */