summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2005-09-11 18:02:28 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2005-09-11 18:02:28 +0000
commit5f2b641bd1b241c22edb6c493f472a4bb446a463 (patch)
tree43e370dd483fdcff55615b0a3d92782d75181f12
parent17f93f987c477cb6765780b9c59e7b41af5740f1 (diff)
Fix " handling in here documents. POSIX says they are not special, so
cat << EOF \" EOF should print \" Fixes PR 4472; testing jmc@ and Adam Montague. ok millert@
-rw-r--r--bin/ksh/exec.c4
-rw-r--r--bin/ksh/lex.c10
-rw-r--r--bin/ksh/lex.h3
3 files changed, 12 insertions, 5 deletions
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 400f7357f80..20f0223504e 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.41 2005/03/30 17:16:37 deraadt Exp $ */
+/* $OpenBSD: exec.c,v 1.42 2005/09/11 18:02:27 otto Exp $ */
/*
* execute command tree
@@ -1187,7 +1187,7 @@ herein(const char *content, int sub)
s = pushs(SSTRING, ATEMP);
s->start = s->str = content;
source = s;
- if (yylex(ONEWORD) != LWORD)
+ if (yylex(ONEWORD|HEREDOC) != LWORD)
internal_errorf(1, "herein: yylex");
source = osource;
shf_puts(evalstr(yylval.cp, 0), shf);
diff --git a/bin/ksh/lex.c b/bin/ksh/lex.c
index b06c590dd1f..5a5345a1903 100644
--- a/bin/ksh/lex.c
+++ b/bin/ksh/lex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.c,v 1.36 2005/03/30 17:16:37 deraadt Exp $ */
+/* $OpenBSD: lex.c,v 1.37 2005/09/11 18:02:27 otto Exp $ */
/*
* lexical analysis and source input
@@ -289,10 +289,16 @@ yylex(int cf)
case '\\':
c = getsc();
switch (c) {
- case '"': case '\\':
+ case '\\':
case '$': case '`':
*wp++ = QCHAR, *wp++ = c;
break;
+ case '"':
+ if ((cf & HEREDOC) == 0) {
+ *wp++ = QCHAR, *wp++ = c;
+ break;
+ }
+ /* FALLTROUGH */
default:
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
diff --git a/bin/ksh/lex.h b/bin/ksh/lex.h
index ce66470b2c2..82cadf151f0 100644
--- a/bin/ksh/lex.h
+++ b/bin/ksh/lex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lex.h,v 1.9 2004/12/18 21:04:52 millert Exp $ */
+/* $OpenBSD: lex.h,v 1.10 2005/09/11 18:02:27 otto Exp $ */
/*
* Source input, lexer and parser
@@ -111,6 +111,7 @@ typedef union {
#define ESACONLY BIT(7) /* only accept esac keyword */
#define CMDWORD BIT(8) /* parsing simple command (alias related) */
#define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
+#define HEREDOC BIT(10) /* parsing heredoc */
#define HERES 10 /* max << in line */