From 47e5ae08a16d8d540ce8db74488530e976b78c33 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 1 Oct 2009 21:40:08 +0000 Subject: [PATCH] sh: Disallow mismatched quotes in backticks (`...`). Due to the amount of code removed by this, it seems that allowing unmatched quotes was a deliberate imitation of System V sh and real ksh. Most other shells do not allow unmatched quotes (e.g. bash, zsh, pdksh, NetBSD /bin/sh, dash). PR: bin/137657 --- bin/sh/parser.c | 8 +------- tools/regression/bin/sh/errors/backquote-error2.0 | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 tools/regression/bin/sh/errors/backquote-error2.0 diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 54a80a715d06..9e861620e5f7 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -82,7 +82,6 @@ struct heredoc { STATIC struct heredoc *heredoclist; /* list of here documents to read */ -STATIC int parsebackquote; /* nonzero if we are inside backquotes */ STATIC int doprompt; /* if set, prompt the user */ STATIC int needprompt; /* true if interactive and at start of line */ STATIC int lasttoken; /* last token read */ @@ -1043,7 +1042,7 @@ readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs) endword: if (syntax == ARISYNTAX) synerror("Missing '))'"); - if (syntax != BASESYNTAX && ! parsebackquote && eofmark == NULL) + if (syntax != BASESYNTAX && eofmark == NULL) synerror("Unterminated quoted string"); if (varnest != 0) { startlinno = plinno; @@ -1303,7 +1302,6 @@ parsesub: { parsebackq: { struct nodelist **nlpp; - int savepbq; union node *n; char *volatile str; struct jmploc jmploc; @@ -1311,11 +1309,9 @@ parsebackq: { int savelen; int saveprompt; - savepbq = parsebackquote; if (setjmp(jmploc.loc)) { if (str) ckfree(str); - parsebackquote = 0; handler = savehandler; longjmp(handler->loc, 1); } @@ -1397,7 +1393,6 @@ done: nlpp = &(*nlpp)->next; *nlpp = (struct nodelist *)stalloc(sizeof (struct nodelist)); (*nlpp)->next = NULL; - parsebackquote = oldstyle; if (oldstyle) { saveprompt = doprompt; @@ -1433,7 +1428,6 @@ done: str = NULL; INTON; } - parsebackquote = savepbq; handler = savehandler; if (arinest || dblquote) USTPUTC(CTLBACKQ | CTLQUOTE, out); diff --git a/tools/regression/bin/sh/errors/backquote-error2.0 b/tools/regression/bin/sh/errors/backquote-error2.0 new file mode 100644 index 000000000000..977c055a2af1 --- /dev/null +++ b/tools/regression/bin/sh/errors/backquote-error2.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +sh -c 'echo `echo .BA"DCODE.` +echo ".BAD"CODE.' 2>&1 | grep -q BADCODE && exit 1 +echo '`"`' | sh -n 2>/dev/null && exit 1 +echo '`'"'"'`' | sh -n 2>/dev/null && exit 1 +exit 0