summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2014-02-27 16:54:43 +0000
committerjilles <jilles@FreeBSD.org>2014-02-27 16:54:43 +0000
commit6891107e84a00af969aa3f785a3ec4d8ba0bd96c (patch)
treef62b533b0847d74aafa265c7c1f443b4366f5e53 /bin/sh
parent4b7832497af6863faa2c8175029568577873fff5 (diff)
downloadFreeBSD-src-6891107e84a00af969aa3f785a3ec4d8ba0bd96c.zip
FreeBSD-src-6891107e84a00af969aa3f785a3ec4d8ba0bd96c.tar.gz
sh: Do not corrupt internal representation if LINENO inner expansion fails.
Example: f() { : ${LINENO+$((1/0))}; } and call this function twice.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/expand.c12
-rw-r--r--bin/sh/tests/builtins/Makefile1
-rw-r--r--bin/sh/tests/builtins/lineno2.010
3 files changed, 17 insertions, 6 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 893ab4b..be07e6c 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -672,10 +672,8 @@ evalvar(char *p, int flag)
again: /* jump here after setting a variable with ${var=text} */
if (varflags & VSLINENO) {
set = 1;
- special = 0;
- val = var;
- p[-1] = '\0'; /* temporarily overwrite '=' to have \0
- terminated string */
+ special = 1;
+ val = NULL;
} else if (special) {
set = varisset(var, varflags & VSNUL);
val = NULL;
@@ -704,7 +702,10 @@ again: /* jump here after setting a variable with ${var=text} */
if (set && subtype != VSPLUS) {
/* insert the value of the variable */
if (special) {
- varvalue(var, varflags & VSQUOTE, subtype, flag);
+ if (varflags & VSLINENO)
+ STPUTBIN(var, p - var - 1, expdest);
+ else
+ varvalue(var, varflags & VSQUOTE, subtype, flag);
if (subtype == VSLENGTH) {
varlenb = expdest - stackblock() - startloc;
varlen = varlenb;
@@ -816,7 +817,6 @@ record:
default:
abort();
}
- p[-1] = '='; /* recover overwritten '=' */
if (subtype != VSNORMAL) { /* skip to end of alternative */
int nesting = 1;
diff --git a/bin/sh/tests/builtins/Makefile b/bin/sh/tests/builtins/Makefile
index 3b1d24b..6f60f84 100644
--- a/bin/sh/tests/builtins/Makefile
+++ b/bin/sh/tests/builtins/Makefile
@@ -87,6 +87,7 @@ FILES+= hash4.0
FILES+= jobid1.0
FILES+= jobid2.0
FILES+= lineno.0 lineno.0.stdout
+FILES+= lineno2.0
FILES+= local1.0
FILES+= local2.0
FILES+= local3.0
diff --git a/bin/sh/tests/builtins/lineno2.0 b/bin/sh/tests/builtins/lineno2.0
new file mode 100644
index 0000000..ddbd104
--- /dev/null
+++ b/bin/sh/tests/builtins/lineno2.0
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+f() {
+ : ${LINENO+${x?}}
+}
+
+unset -v x
+command eval f 2>/dev/null && exit 3
+x=1
+f
OpenPOWER on IntegriCloud