From nobody Fri Aug 01 23:13:01 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 4bv1vf1lYsz63Fp9; Fri, 01 Aug 2025 23:13:02 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bv1vd4fGMz3VHm; Fri, 01 Aug 2025 23:13:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754089981; 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=AM7kF7qtvM59CU9QwuCpfifXrP6yb2D/BQynWLyMRUY=; b=dV0RaXNSmBLh8C+5Hx+o6TA6dz4XMD9aKTp6WT+TUnQT6EjPhgnOHO1MqEKnxliGAtxHeq h9VsUerD3tnG38YuZ3961z6opa2MnBB3K0YA8VrtL/VGeP367mnGCynZyf81vUNxToWK2W 3cGv045lN58z1Ono3dH888SarRYwyMjowbcbb6H02Tk2tBzwDb/fr/BTzB4Fm+YIQQcARO pe2QxLZtnglB/0GOL9zy6Q6DnRuP0pUo4K96y0dlVKRf9jVthZ0p1r++9TsmVqyfN3IEvA jkkvDrX240U8mKT6hX1/6w7mMUjSguE8M5bHQRIN4B0sqMyIKWouPbJ8kGew7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754089981; 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=AM7kF7qtvM59CU9QwuCpfifXrP6yb2D/BQynWLyMRUY=; b=RrdiTE52Ap/fbPL6M7NrsNgFDboPK46NiClT6gnWxx2JzkOXLd+5Bfr69EYnUmFZOoCQoA uwKYVDH7xbRvfEh142PI5GpwxcACihien9N/UK1e26qf6wWSd+P+mFJTeujOFIMMTI0Ofd Wd/D9g6gYtG+vJNQShEl7QaDyw8PORvcXw7R7lZf7yqh54VX3/tOIwYsPJYYk7aQ3SBW1b 4Iucc2iXs4yEpNlRIz/z9IZULTFP5JkxZPBcM92Ma2PHucds8q7uT9sQuNdIWY3Zd1WqW+ sdGWl0EvrR3CYNLR9ELt17KW16lSVdF8Hro8V4oR0qal4mMEn0pPYwSVzUf7Pg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754089981; a=rsa-sha256; cv=none; b=jIbnYv4lOq1Ju8KXmqO8JAT1uXWMuBBvrFMezN7a4KiiZr5cUr2cFlzyDVuhDFcGC5at7J oLBPLxiRXD889gdf5tioruDLBtUIPhCvdW/mFmlKbnH2illGfjObcg+oPQPrvIzjSAybaG snHYISGyTGtqqV9N3wNfdTzvP8pi852awDCH9M1QwQRBpOoQS6HmViXqq8kcP/xe7Dps0Q tK3VbM2dPEwV/5x+sujw40BuHE90JlamdQUomdHhDcswEYutrFScRa9LPskrtdGx5ahc45 MIY3MIRHa8HNbVWrjp9Dq5Hb6AXV2W4JUP96ZkFNtDWthR7gcRGO3YNvdl7KlA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bv1vd3bFqz17Tw; Fri, 01 Aug 2025 23:13:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 571ND1tq053484; Fri, 1 Aug 2025 23:13:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 571ND11E053481; Fri, 1 Aug 2025 23:13:01 GMT (envelope-from git) Date: Fri, 1 Aug 2025 23:13:01 GMT Message-Id: <202508012313.571ND11E053481@gitrepo.freebsd.org> 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=B8rgrav?= Subject: git: 65bae451c23b - main - kyua: Stop using readdir_r() 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 65bae451c23b8d61b2433259d8e707250660eeff Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=65bae451c23b8d61b2433259d8e707250660eeff commit 65bae451c23b8d61b2433259d8e707250660eeff Author: Dag-Erling Smørgrav AuthorDate: 2025-08-01 23:11:26 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-08-01 23:11:56 +0000 kyua: Stop using readdir_r() It cannot be used safely, and Kyua doesn't even pretend to try. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: igoro Differential Revision: https://reviews.freebsd.org/D51680 --- contrib/kyua/utils/fs/directory.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/contrib/kyua/utils/fs/directory.cpp b/contrib/kyua/utils/fs/directory.cpp index f82fe88f86dc..b73741aa544d 100644 --- a/contrib/kyua/utils/fs/directory.cpp +++ b/contrib/kyua/utils/fs/directory.cpp @@ -127,16 +127,9 @@ struct utils::fs::detail::directory_iterator::impl : utils::noncopyable { /// not. A null pointer means an invalid iterator. ::DIR* _dirp; - /// Raw representation of the system directory entry. - /// - /// We need to keep this at the class level so that we can use the - /// readdir_r(3) function. - ::dirent _dirent; - /// Custom representation of the directory entry. /// - /// This is separate from _dirent because this is the type we return to the - /// user. We must keep this as a pointer so that we can support the common + /// We must keep this as a pointer so that we can support the common /// operators (* and ->) over iterators. std::unique_ptr< directory_entry > _entry; @@ -192,22 +185,23 @@ struct utils::fs::detail::directory_iterator::impl : utils::noncopyable { /// It is possible to use this function on a new directory_entry object to /// initialize the first entry. /// - /// \throw system_error If the call to readdir_r fails. + /// \throw system_error If the call to readdir fails. void next(void) { ::dirent* result; - if (::readdir_r(_dirp, &_dirent, &result) == -1) { + errno = 0; + if ((result = ::readdir(_dirp)) == NULL && errno != 0) { const int original_errno = errno; - throw fs::system_error(F("readdir_r(%s) failed") % _path, + throw fs::system_error(F("readdir(%s) failed") % _path, original_errno); } if (result == NULL) { _entry.reset(); close(); } else { - _entry.reset(new directory_entry(_dirent.d_name)); + _entry.reset(new directory_entry(result->d_name)); } } };