sh: Fix use-after-free if a trap replaces itself.
MFC after: 1 week
This commit is contained in:
parent
ad3ecc2025
commit
f30e8c7e71
@ -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
|
||||
|
10
bin/sh/tests/builtins/trap17.0
Normal file
10
bin/sh/tests/builtins/trap17.0
Normal 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 ]
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user