git: 805f6029286e - stable/13 - kyua: Stop using readdir_r()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 08 Aug 2025 22:09:25 UTC
The branch stable/13 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=805f6029286e2045326877e8d06ae1adc2e41862
commit 805f6029286e2045326877e8d06ae1adc2e41862
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-08-01 23:11:26 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-08-08 19:46:33 +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
(cherry picked from commit 65bae451c23b8d61b2433259d8e707250660eeff)
---
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 ff7ad5e34357..9103c2377c34 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::auto_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(NULL);
close();
} else {
- _entry.reset(new directory_entry(_dirent.d_name));
+ _entry.reset(new directory_entry(result->d_name));
}
}
};