From nobody Wed Nov 19 20:32:18 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dBY7Q5z6Wz6JDY1 for ; Wed, 19 Nov 2025 20:32:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dBY7Q3Kmsz3vpY for ; Wed, 19 Nov 2025 20:32:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763584338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=agUbLijKfE6D9POo/jV7YQgU08zmsO7wh/qxCjSsueI=; b=qOP3KL5K0rnlp5YjNhcVcJqxB+kzVDBQO3n+E9FZgPeLGzkjWjZz3x6FLrstIQSrVoovc0 Ilj1kJLkdoOHNFQDCfb64cA2h5GyXw8hBSuOrljmSE73clcRY4okk+FznA4xU3NLcq+PY+ mCTPltHhR4gn2T8bly65jZGoCuSBi1U05mpB9t3SUkuNC447gJjxVisl9LCQIGwc0e+/+F wXTDnaRJqd3JpWDRFerTJpxN+RRY3YmnFwVBXGxVlGPzAYbG+/tb1+lJTKSdGlWfBf+44c 28DHuvnk/c61q33GPFRRQ6ARRhfFa2lGUXzEVVKJW/mD7Tu6ollj7TiKngLcrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763584338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=agUbLijKfE6D9POo/jV7YQgU08zmsO7wh/qxCjSsueI=; b=Mc38TasK4duMkGPLkP9SA6RJLo1/Eo99HkLuHP4NDMR/WoYjiJqihxaRpQFMzEVGLXmdjQ FWMW6HfGdwwpTagJT2UsZEgNGLlBfOx7VUTXJ0nQiPgr2MqB4L4IoGPmDIEhpKtTcfvEhE vuUsERpVDYW0lu/CaXwAaMEoye7lsyyh9Yj72rHwJUyJcmm0YCPP9yWO7J6j1uJzJX5nOO jRhpxxzZR8WVCSoa2ACgZPuVfsw1vCMZD+VitInQYWDwrNZMKbvZ6ZTEr1yKlw2IS7UfUP 9A418XsU0qt/xsdb0V4YDTeKZyRKmCGISurYW82enc1eD+cSGG42EG6u8XW++g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763584338; a=rsa-sha256; cv=none; b=Li6uwJUkLa4GFao2oz+TKOEfq0P6OFsCrxhLhCAGMw48KvPbY/9oIGjvvr+v3jQC3UZDbD g2/e/CU8uKfd4Ks+6nxx2Z2c9wsexsKn+Dj9Q/BC7RvoctLzwK4sJ11sEdMCGLLC5+D+ZL C8uUtcEpazQXmYpTt4KbtLXGs0w+5+U05KB7ELI5xdFNI8tCSqo993nJGS16lNUPv1xo8a aMzMI1gORJM5tbdrouuV3tMpqjbad39uyfengA8NwAB5ZZ/xqWbII/hBd382VgR1ajWoVm GZq8MqualKM09rnDJyTgnNmEdLMlThPVzqZxJX3YWy9QKBHcdtUmBLPVYIy0Tw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dBY7Q2fc8zvfd for ; Wed, 19 Nov 2025 20:32:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2c970 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 19 Nov 2025 20:32:18 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jilles Tjoelker Subject: git: f44ac8cc9c10 - main - sh: Fix job pointer invalidation with trapsasync List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jilles X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f44ac8cc9c10d7305223a10b8dbd8e234388cc73 Auto-Submitted: auto-generated Date: Wed, 19 Nov 2025 20:32:18 +0000 Message-Id: <691e2952.2c970.6d79d13c@gitrepo.freebsd.org> The branch main has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=f44ac8cc9c10d7305223a10b8dbd8e234388cc73 commit f44ac8cc9c10d7305223a10b8dbd8e234388cc73 Author: Jilles Tjoelker AuthorDate: 2025-11-17 17:42:01 +0000 Commit: Jilles Tjoelker CommitDate: 2025-11-19 20:30:39 +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 --- 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 0aaff5e1e140..a4cd76473921 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -1078,6 +1078,7 @@ waitforjob(struct job *jp, int *signaled) #if JOBS int propagate_int = jp->jobctl && jp->foreground; #endif + int jobindex; int status; int st; @@ -1085,8 +1086,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 53cb97db9393..dde562a082cd 100644 --- a/bin/sh/tests/execution/Makefile +++ b/bin/sh/tests/execution/Makefile @@ -18,6 +18,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