mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
sh: Fix job pointer invalidation with trapsasync
Calling dotrap() can do almost anything, including reallocating the
jobtab array. Convert the job pointer to an index before calling
dotrap() and then restore a proper job pointer afterwards.
PR: 290330
Reported by: bdrewery
Reviewed by: bdrewery
Differential Revision: https://reviews.freebsd.org/D53793
(cherry picked from commit f44ac8cc9c)
This commit is contained in:
1 parent
c0dcdc3dec
commit
21d665d7dd
3 files changed
+15
-1
No files matched your search
+5
-1
@@ -1084,6 +1084,7 @@ waitforjob(struct job *jp, int *signaled)
|
||||
#if JOBS
|
||||
int propagate_int = jp->jobctl && jp->foreground;
|
||||
#endif
|
||||
int jobindex;
|
||||
int status;
|
||||
int st;
|
||||
|
||||
@@ -1091,8 +1092,11 @@ waitforjob(struct job *jp, int *signaled)
|
||||
TRACE(("waitforjob(%%%td) called\n", jp - jobtab + 1));
|
||||
while (jp->state == 0)
|
||||
if (dowait(DOWAIT_BLOCK | (Tflag ? DOWAIT_SIG |
|
||||
DOWAIT_SIG_TRAP : 0), jp) == -1)
|
||||
DOWAIT_SIG_TRAP : 0), jp) == -1) {
|
||||
jobindex = jp - jobtab;
|
||||
dotrap();
|
||||
jp = jobtab + jobindex;
|
||||
}
|
||||
#if JOBS
|
||||
if (jp->jobctl) {
|
||||
if (ttyfd >= 0 && tcsetpgrp(ttyfd, rootpid) < 0)
|
||||
|
||||
@@ -19,6 +19,7 @@ ${PACKAGE}FILES+= bg10.0 bg10.0.stdout
|
||||
${PACKAGE}FILES+= bg11.0
|
||||
${PACKAGE}FILES+= bg12.0
|
||||
${PACKAGE}FILES+= bg13.0
|
||||
${PACKAGE}FILES+= bg14.0
|
||||
${PACKAGE}FILES+= env1.0
|
||||
${PACKAGE}FILES+= fork1.0
|
||||
${PACKAGE}FILES+= fork2.0
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
T=`mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXXXX`
|
||||
trap 'rm -rf "$T"' 0
|
||||
cd "$T" || exit 3
|
||||
mkfifo fifo1 || exit 3
|
||||
set -T
|
||||
trap "for i in 1 2 3 4; do sleep 1 & done" USR1
|
||||
sleep 1 &
|
||||
{ kill -USR1 "$$"; echo .; } >fifo1 &
|
||||
(read dummy <fifo1)
|
||||
Reference in new issue
Block a user