summaryrefslogtreecommitdiffstats
path: root/bin/sh/tests
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2017-03-12 18:38:03 +0000
committerjilles <jilles@FreeBSD.org>2017-03-12 18:38:03 +0000
commitfad9bc33a21dea59b9141f4c4a818b8da7940f02 (patch)
tree241f1c36998f139d25db6d4ca988e49053996a94 /bin/sh/tests
parentc52ab07b68286c4c43d14217015a2fc847019e99 (diff)
downloadFreeBSD-src-fad9bc33a21dea59b9141f4c4a818b8da7940f02.zip
FreeBSD-src-fad9bc33a21dea59b9141f4c4a818b8da7940f02.tar.gz
MFC r314686: sh: Fix crash if a -T trap is taken during command substitution
Code like t=$(stat -f %m "$file") segfaulted if -T was active and a trap was taken while the shell was waiting for the child process to finish. What happened was that the dotrap() call in waitforjob() was hit. This re-entered command execution (including expand.c) at a point not expected by expbackq(), and global state (unallocated stack string and argbackq) was corrupted. To fix this, change expbackq() to prepare for command execution to be re-entered. Reported by: bdrewery
Diffstat (limited to 'bin/sh/tests')
-rw-r--r--bin/sh/tests/expansion/Makefile2
-rw-r--r--bin/sh/tests/expansion/cmdsubst21.06
-rw-r--r--bin/sh/tests/expansion/cmdsubst22.06
3 files changed, 14 insertions, 0 deletions
diff --git a/bin/sh/tests/expansion/Makefile b/bin/sh/tests/expansion/Makefile
index 3c0dfa3..c062232 100644
--- a/bin/sh/tests/expansion/Makefile
+++ b/bin/sh/tests/expansion/Makefile
@@ -42,6 +42,8 @@ ${PACKAGE}FILES+= cmdsubst17.0
${PACKAGE}FILES+= cmdsubst18.0
${PACKAGE}FILES+= cmdsubst19.0
${PACKAGE}FILES+= cmdsubst20.0
+${PACKAGE}FILES+= cmdsubst21.0
+${PACKAGE}FILES+= cmdsubst22.0
${PACKAGE}FILES+= export1.0
${PACKAGE}FILES+= export2.0
${PACKAGE}FILES+= export3.0
diff --git a/bin/sh/tests/expansion/cmdsubst21.0 b/bin/sh/tests/expansion/cmdsubst21.0
new file mode 100644
index 0000000..87ff6a9
--- /dev/null
+++ b/bin/sh/tests/expansion/cmdsubst21.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$($SH -c "kill $$")y" = xy ] && [ "$trapped" = x ]
diff --git a/bin/sh/tests/expansion/cmdsubst22.0 b/bin/sh/tests/expansion/cmdsubst22.0
new file mode 100644
index 0000000..97c6c98
--- /dev/null
+++ b/bin/sh/tests/expansion/cmdsubst22.0
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+set -T
+trapped=''
+trap "trapped=x$trapped" TERM
+[ "x$(:; kill $$)y" = xy ] && [ "$trapped" = x ]
OpenPOWER on IntegriCloud