From d24941bb85f8ccc41a9894871e7cca7a02de066c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Mon, 17 Jul 2023 19:58:39 -0400 Subject: bftw: Check that file->fd == bfs_dirfd(file->dir) earlier This has the potential to fail on at least one known platform: macports with the legacysupport implementation of fdopendir(). Link: https://github.com/macports/macports-ports/pull/19047#issuecomment-1636059809 --- src/bftw.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/bftw.c b/src/bftw.c index 9d85966..f8d0ac5 100644 --- a/src/bftw.c +++ b/src/bftw.c @@ -219,7 +219,6 @@ static void bftw_file_close(struct bftw_cache *cache, struct bftw_file *file) { bfs_assert(file->pincount == 0); if (file->dir) { - bfs_assert(file->fd == bfs_dirfd(file->dir)); bfs_closedir(file->dir); bftw_freedir(cache, file->dir); file->dir = NULL; @@ -354,7 +353,9 @@ static void bftw_file_set_dir(struct bftw_cache *cache, struct bftw_file *file, bfs_assert(!file->dir); file->dir = dir; - if (file->fd < 0) { + if (file->fd >= 0) { + bfs_assert(file->fd == bfs_dirfd(dir)); + } else { file->fd = bfs_dirfd(dir); bftw_cache_add(cache, file); } -- cgit v1.2.3