sh: Fix use-after-free if a trap replaces itself.

MFC after:	1 week
This commit is contained in:
Jilles Tjoelker 2016-03-28 18:58:40 +00:00
parent ad3ecc2025
commit f30e8c7e71
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=297360
3 changed files with 15 additions and 1 deletions

View File

@ -149,6 +149,7 @@ FILES+= trap13.0
FILES+= trap14.0
FILES+= trap15.0
FILES+= trap16.0
FILES+= trap17.0
FILES+= trap2.0
FILES+= trap3.0
FILES+= trap4.0

View File

@ -0,0 +1,10 @@
# $FreeBSD$
# This use-after-free bug probably needs non-default settings to show up.
v1=nothing v2=nothing
trap 'trap "echo bad" USR1
v1=trap_received
v2=trap_invoked
:' USR1
kill -USR1 "$$"
[ "$v1.$v2" = trap_received.trap_invoked ]

View File

@ -412,6 +412,7 @@ onsig(int signo)
void
dotrap(void)
{
struct stackmark smark;
int i;
int savestatus, prev_evalskip, prev_skipcount;
@ -445,7 +446,9 @@ dotrap(void)
last_trapsig = i;
savestatus = exitstatus;
evalstring(trap[i], 0);
setstackmark(&smark);
evalstring(stsavestr(trap[i]), 0);
popstackmark(&smark);
/*
* If such a command was not