From nobody Thu Feb 5 15:27:33 2026 X-Original-To: dev-commits-src-branches@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 4f6Lgp5bhlz6Ql4G for ; Thu, 05 Feb 2026 15:27:34 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4f6Lgp08wlz3XWN for ; Thu, 05 Feb 2026 15:27:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1770305254; 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=qUhuPGo7cC5ncfyC88SDHIiOj8MxWHmI4SUE56ntIUI=; b=KYnwF5MHVmuEQYs19HdamX9fRPbB9dQR6VtqJZsNG2zRp13ExeH6rF+VnWkqDqdxycwoYt KCa7HtT050IlS3qu6te1unh73/PyftmUhiVe6azW5T4AbpAhiGnNOBfh5v11jIa5c7TmWu NGO1SbbezQnxufMvUZevnN/C7nEdYurJ9CVQXlkZN5JZ7a6a/syTg03YbOLIdHZZLDahJ1 33U0hEw4HAg8saYH+0royedo3NHf2jjL2imlqs3tENRT4dkIz6Zgp00GFgsPxnQuj/8uCT 0QSjULgOigQjTFaI4entOloR4+A3ipp5ze7ac+fBrnh8kYNVTHckMVVA34wE5g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1770305254; a=rsa-sha256; cv=none; b=UToS0Cwy+O59iLcaiaq6+uGtUkXwV539JZvndy1OUzO17fz+97wY6pnMryIH4bOSOaePTV HsVoZKw/vif26wMZyEJG5yvU6Extb/MnMWSUu4F8na/Xx6DXeTzUbkOGxe+tZObXVH+3+d cbWumCJ8S/K0t2u4dDSeZD3ReCA7BV4v+zDup5gMCdPMUcGl2YkrRJV0W9g84Nv2FcHKCq hJK5MmivKwa33O2+wrM0wnWeeGw77KoSUv5gRR+ejV9LxHmj927er+oE5hgQUFYUpxMCG4 576JosngM1HcjACi3dnnXOaumvnrWJh4S+321lSR5e0h2FVPLJjSHzTU+iosBw== 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=1770305254; 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=qUhuPGo7cC5ncfyC88SDHIiOj8MxWHmI4SUE56ntIUI=; b=JZ1StKmejIFyKqYCM9lSHV+B2H4cTbB7hClmpL/tBIwkJpbI4wbOUKcPLCBA3Szy/gpHIq CpkBfhLTGxD7+//UYrTJnLObUSOCZkpkLGAigO1Ma8F1EPQAR2OldODcZEg21uggWg2PcS t+MNiSLpDlT2cH4/mnxT7k1VygUpjAK30kIA0WDE3RKZN+F3eeYU6Rr3SrtF/oC4/aXEZg 9E7n909+5pSlzrLLg5klt793X/0z1was49CdOvcln9/UiilZytM14FotDHOd8cVy5x3wLR J/8L8/v6As7hwIu5neU333mT6yjaN7Te5GN2uq5w6I9ucqAYRl0qkS0SFDHWZA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4f6Lgn6Z1WzbH1 for ; Thu, 05 Feb 2026 15:27:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3fcba by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Feb 2026 15:27:33 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: 77dedead8539 - stable/14 - libc: Improve POSIX conformance of dirfd() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 77dedead8539c76d1f452c2c0073ee13ed7cf54a Auto-Submitted: auto-generated Date: Thu, 05 Feb 2026 15:27:33 +0000 Message-Id: <6984b6e5.3fcba.488124be@gitrepo.freebsd.org> The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=77dedead8539c76d1f452c2c0073ee13ed7cf54a commit 77dedead8539c76d1f452c2c0073ee13ed7cf54a Author: Dag-Erling Smørgrav AuthorDate: 2026-02-02 15:46:57 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2026-02-05 14:48:36 +0000 libc: Improve POSIX conformance of dirfd() POSIX states that dirfd() should set errno to EINVAL and return -1 if dirp does not refer to a valid directory stream. Our interpretation is that this applies if dirp is null or the file descriptor associated with it is negative. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55025 (cherry picked from commit 5074d5c9845e142883cdbb9ad212be66e57615d0) libc: Fix missing include Although not needed on FreeBSD due to namespace pollution, we should technically #include to secure a definition of NULL. Fixes: 5074d5c9845e ("libc: Improve POSIX conformance of dirfd()") (cherry picked from commit 1c00d5a3b234ef937d848956027e9de5ea8010f9) --- lib/libc/gen/directory.3 | 14 +++++++++++++- lib/libc/gen/dirfd.c | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/directory.3 b/lib/libc/gen/directory.3 index 3a121dcafb8c..ee78202ddc3e 100644 --- a/lib/libc/gen/directory.3 +++ b/lib/libc/gen/directory.3 @@ -258,7 +258,9 @@ The function returns 0 on success and -1 on failure. The .Fn fdclosedir -function returns an open file descriptor on success and -1 on failure. +and +.Fn dirfd +functions return an open file descriptor on success and -1 on failure. .Sh ERRORS The .Fn opendir @@ -329,6 +331,16 @@ function may also fail and set .Va errno for any of the errors specified for the routine .Xr close 2 . +.Pp +The +.Fn dirfd +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa dirp +argument does not refer to a valid directory stream. +.El .Sh SEE ALSO .Xr close 2 , .Xr lseek 2 , diff --git a/lib/libc/gen/dirfd.c b/lib/libc/gen/dirfd.c index ba8f52845b4e..984e69b9ae9a 100644 --- a/lib/libc/gen/dirfd.c +++ b/lib/libc/gen/dirfd.c @@ -28,6 +28,8 @@ #include "namespace.h" #include +#include +#include #include "un-namespace.h" #include "gen-private.h" @@ -35,5 +37,9 @@ int dirfd(DIR *dirp) { + if (dirp == NULL || _dirfd(dirp) < 0) { + errno = EINVAL; + return (-1); + } return (_dirfd(dirp)); }