FreeBSD Bugzilla – Attachment 231923 Details for
Bug 262038
fts(3): Check for readdir(3) errors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Check for readdir errors
patch-fts.txt (text/plain), 1.59 KB, created by
Ganael LAPLANCHE
on 2022-02-18 18:00:04 UTC
(
hide
)
Description:
Check for readdir errors
Filename:
MIME Type:
Creator:
Ganael LAPLANCHE
Created:
2022-02-18 18:00:04 UTC
Size:
1.59 KB
patch
obsolete
>diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c >index d0705e12377..4213d030836 100644 >--- a/lib/libc/gen/fts.c >+++ b/lib/libc/gen/fts.c >@@ -604,6 +604,15 @@ fts_set_clientptr(FTS *sp, void *clientptr) > sp->fts_clientptr = clientptr; > } > >+static struct dirent * >+fts_safe_readdir(DIR *dirp) >+{ >+ errno = 0; >+ if (!dirp) >+ return (NULL); >+ return readdir(dirp); >+} >+ > /* > * This is the tricky part -- do not casually change *anything* in here. The > * idea is to build the linked list of entries that are used by fts_children >@@ -733,7 +742,7 @@ fts_build(FTS *sp, int type) > > /* Read the directory, attaching each entry to the `link' pointer. */ > doadjust = 0; >- for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) { >+ for (head = tail = NULL, nitems = 0; (dp = fts_safe_readdir(dirp));) { > dnamlen = dp->d_namlen; > if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) > continue; >@@ -819,6 +828,20 @@ mem1: saved_errno = errno; > } > ++nitems; > } >+ >+ /* >+ * The only way to distinguish between "no more files" and readdir >+ * error is checking errno when readdir() returns NULL. >+ */ >+ if (errno) { >+ cur->fts_errno = errno; >+ /* >+ * If we've not read any items yet, treat >+ * the error as if we can't access the dir. >+ */ >+ cur->fts_info = nitems ? FTS_ERR : FTS_DNR; >+ } >+ > if (dirp) > (void)closedir(dirp); > >@@ -855,7 +878,8 @@ mem1: saved_errno = errno; > > /* If didn't find anything, return NULL. */ > if (!nitems) { >- if (type == BREAD) >+ if (type == BREAD && >+ cur->fts_info != FTS_DNR && cur->fts_info != FTS_ERR) > cur->fts_info = FTS_DP; > return (NULL); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 262038
:
231923
|
232355
|
232470
|
232739