From nobody Wed Feb 25 21:12:56 2026 X-Original-To: dev-commits-src-all@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 4fLnP461Hmz6TnG6 for ; Wed, 25 Feb 2026 21:12:56 +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" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fLnP43pnyz47K6 for ; Wed, 25 Feb 2026 21:12:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772053976; 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=C/pGglxByI/B98SyYAlYgs9odB4GIpOHR+NGT1Oqejs=; b=vATClW1dfUyHfs4lTlyMoMicsftwylM9mOUhIwO5z9KpJcHpDSe0Qxyy4IhFi4m4UTr+F4 81TopoMOYRlK3pfMsqqr7WglpzFWyPjiKDB7zCjbTL7uvKaByEYNlRy7N8tiqNK6NfWMVs SBIurF84ZE8CkJuKbf2k4XYqj/ioNmwT6t6Xojx6Z6uu7AqzOQPycu41K8IrMG9TwxFnXm apFJS/4HL8OmcemJxfT+AIqaHJMLLrr+PuXTZ7ov/yyiWHo1D3TOkqeFKn+mn6u+70Kcx3 LyvHmoTMGLyqqK7h3boN/sATS8PrELF7+/YuLSM1vrHbCB+jTBfuheoKvlrQOA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1772053976; a=rsa-sha256; cv=none; b=hwFQBZEcX+fAYlW5/bsz0oREVOWXJ4MSMmdK0I6k6kihapIBqHKXtDUBiLobpYRvd3h5e8 xB2uYkc3upryrs+hy1xVvhLOpZfACRK9PxRBxoLJKh/A/7Mgfe1BLSBlybYfTkvwnXz9ob cgX0dvgAO4MeBZQXaMDxslPm5i94hU6SzycR9cG6oAqvDaeMt4RKUAROwV2fSIoque/GC2 UPfOszHu66biYXSlW+11HNaG81fK+XTPsNodMK02YbTbwLbS2o18cGOEcRIhKrCs2MV1Qc Kd8r4RnzYjh/1aZzVSR07UOurXozeIWYdwpJgLYOC39lX49P/7NTkW9G5MPeug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1772053976; 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=C/pGglxByI/B98SyYAlYgs9odB4GIpOHR+NGT1Oqejs=; b=PtEcReBrbV20jUPy5IokiIzV4UXm1wwlwm10w5/jiaDCnnUwGpwflKvGxIOSlSHdDdyE3P u3f8zyy/o+Oxcway28SgFT4aUpUjWwYVKarvjZX46V/U7VjCjEaQZjLSLw7Vpsf3sum4+Y 7+Sl70fzk0I7FlqaefRwV9OmQqCnaiSbxtjDRVN2lEMlNSMZV0PyDWyjx2vfjVsON1PIkA 6SToOpIf1EL5/jtio62w9yNX++Dzls8tCXajBYhCgHexJsLEBTw99p6I8QYC4CX9LHNchC 4K0TIaTMPO0fvymTw/hL27CHDSd+RTA90NE+Ji5bxR5ZcT4PieO/N17fTg7umQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fLnP430Wtz1HFq for ; Wed, 25 Feb 2026 21:12:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 30799 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 25 Feb 2026 21:12:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 8ae3f4499194 - main - system(3): Fix null case List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8ae3f44991948cc97b09adc248a9a46db71bf9e0 Auto-Submitted: auto-generated Date: Wed, 25 Feb 2026 21:12:56 +0000 Message-Id: <699f65d8.30799.72e465a3@gitrepo.freebsd.org> The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=8ae3f44991948cc97b09adc248a9a46db71bf9e0 commit 8ae3f44991948cc97b09adc248a9a46db71bf9e0 Author: Dag-Erling Smørgrav AuthorDate: 2026-02-25 21:12:42 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-25 21:12:42 +0000 system(3): Fix null case Our manual page states that if given a null pointer, system() returns non-zero if the shell is available and zero if it is not. This is consistent with the C standard's description of system(), but it is not what we actually do. What we actually do is always return non-zero, as required by POSIX. As the POSIX rationale explains, implementing the logic required by the C standard does not violate POSIX, since a conforming system always has a shell, therefore the logic will always return non-zero. Since our libc is commonly used in non-conforming situations such as chroots or thin jails, we should implement the full logic required by the C standard. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: obiwac, bnovkov, kevans Differential Revision: https://reviews.freebsd.org/D55484 --- lib/libc/stdlib/system.c | 2 +- lib/libc/tests/stdlib/system_test.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index 17dd63eb52f9..94f7460c9b68 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -64,7 +64,7 @@ __libc_system(const char *command) pid_t pid; if (command == NULL) /* just checking... */ - return (1); + return (eaccess(_PATH_BSHELL, X_OK) == 0); /* * If we are the first concurrent instance, ignore SIGINT and diff --git a/lib/libc/tests/stdlib/system_test.c b/lib/libc/tests/stdlib/system_test.c index 713e4bb0f87a..b6a31583d52d 100644 --- a/lib/libc/tests/stdlib/system_test.c +++ b/lib/libc/tests/stdlib/system_test.c @@ -57,10 +57,20 @@ ATF_TC(system_null); ATF_TC_HEAD(system_null, tc) { atf_tc_set_md_var(tc, "descr", "system(NULL)"); + atf_tc_set_md_var(tc, "require.user", "root"); } ATF_TC_BODY(system_null, tc) { + /* First, test in a normal environment */ ATF_REQUIRE_EQ(1, system(NULL)); + + /* Now enter an empty chroot */ + ATF_REQUIRE_EQ(0, chroot(".")); + ATF_REQUIRE_EQ(0, chdir("/")); + + /* Test again with no shell available */ + ATF_REQUIRE_EQ(0, system(NULL)); + ATF_REQUIRE_EQ(W_EXITCODE(127, 0), system("true")); } /*