diff options
author | jilles <jilles@FreeBSD.org> | 2015-09-13 13:31:51 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-09-13 13:31:51 +0000 |
commit | e646354b485aa16f77c0346625c3c2834f3b8df5 (patch) | |
tree | 2e65a8f6e516e7305812aeb63901748dc8b4bc93 /bin/sh | |
parent | 44b5ad695538d1ce6a4e50da128435775460329a (diff) | |
download | FreeBSD-src-e646354b485aa16f77c0346625c3c2834f3b8df5.zip FreeBSD-src-e646354b485aa16f77c0346625c3c2834f3b8df5.tar.gz |
MFC r287081: sh: Don't create bad parse result when postponing a bad
substitution error.
An invalid substitution like ${var@} does not cause a parse error but is
stored in the intermediate representation, to be written as part of the
error message. If there is a CTL* byte in the stored part, this confuses
some code such as the code to skip an unused alternative such as in
${var-alternative}.
To keep things simple, do not store CTL* bytes.
Found with afl-fuzz.
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/parser.c | 5 | ||||
-rw-r--r-- | bin/sh/tests/errors/Makefile | 2 | ||||
-rw-r--r-- | bin/sh/tests/errors/bad-parm-exp7.0 | 4 | ||||
-rw-r--r-- | bin/sh/tests/errors/bad-parm-exp8.0 | 4 |
4 files changed, 13 insertions, 2 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index e6e9f82..b577a8a 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1671,7 +1671,7 @@ varname: pungetc(); else if (c == '\n' || c == PEOF) synerror("Unexpected end of line in substitution"); - else + else if (BASESYNTAX[c] != CCTL) USTPUTC(c, out); } if (subtype == 0) { @@ -1687,7 +1687,8 @@ varname: synerror("Unexpected end of line in substitution"); if (flags == VSNUL) STPUTC(':', out); - STPUTC(c, out); + if (BASESYNTAX[c] != CCTL) + STPUTC(c, out); subtype = VSERROR; } else subtype = p - types + VSNORMAL; diff --git a/bin/sh/tests/errors/Makefile b/bin/sh/tests/errors/Makefile index 9f8b0f2..ab04f14 100644 --- a/bin/sh/tests/errors/Makefile +++ b/bin/sh/tests/errors/Makefile @@ -17,6 +17,8 @@ FILES+= bad-parm-exp3.2 bad-parm-exp3.2.stderr FILES+= bad-parm-exp4.2 bad-parm-exp4.2.stderr FILES+= bad-parm-exp5.2 bad-parm-exp5.2.stderr FILES+= bad-parm-exp6.2 bad-parm-exp6.2.stderr +FILES+= bad-parm-exp7.0 +FILES+= bad-parm-exp8.0 FILES+= option-error.0 FILES+= redirection-error.0 FILES+= redirection-error2.2 diff --git a/bin/sh/tests/errors/bad-parm-exp7.0 b/bin/sh/tests/errors/bad-parm-exp7.0 new file mode 100644 index 0000000..b8562fb --- /dev/null +++ b/bin/sh/tests/errors/bad-parm-exp7.0 @@ -0,0 +1,4 @@ +# $FreeBSD$ + +v=1 +eval ": $(printf '${v-${\372}}')" diff --git a/bin/sh/tests/errors/bad-parm-exp8.0 b/bin/sh/tests/errors/bad-parm-exp8.0 new file mode 100644 index 0000000..28f00cd --- /dev/null +++ b/bin/sh/tests/errors/bad-parm-exp8.0 @@ -0,0 +1,4 @@ +# $FreeBSD$ + +v=1 +eval ": $(printf '${v-${w\372}}')" |