Date: Sun, 01 Feb 2026 21:08:42 +0000 From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: e45b89582fcb - stable/13 - sh: Fix job pointer invalidation with trapsasync Message-ID: <697fc0da.37b79.733fb104@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/13 has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=e45b89582fcbf4f65593303bf41a28ed6071460f commit e45b89582fcbf4f65593303bf41a28ed6071460f Author: Jilles Tjoelker <jilles@FreeBSD.org> AuthorDate: 2025-11-17 17:42:01 +0000 Commit: Jilles Tjoelker <jilles@FreeBSD.org> CommitDate: 2026-02-01 14:35:59 +0000 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 f44ac8cc9c10d7305223a10b8dbd8e234388cc73) --- bin/sh/jobs.c | 6 +++++- bin/sh/tests/execution/Makefile | 1 + bin/sh/tests/execution/bg14.0 | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index d5d8ca978bb5..1cd8f4443f73 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1082,6 +1082,7 @@ waitforjob(struct job *jp, int *signaled) #if JOBS int propagate_int = jp->jobctl && jp->foreground; #endif + int jobindex; int status; int st; @@ -1089,8 +1090,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) diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile index 2b4f88db989c..e201cfdecf87 100644 --- a/bin/sh/tests/execution/Makefile +++ b/bin/sh/tests/execution/Makefile @@ -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 diff --git a/bin/sh/tests/execution/bg14.0 b/bin/sh/tests/execution/bg14.0 new file mode 100644 index 000000000000..e27f77e9b7b3 --- /dev/null +++ b/bin/sh/tests/execution/bg14.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)home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?697fc0da.37b79.733fb104>
