diff options
author | jilles <jilles@FreeBSD.org> | 2015-04-19 13:28:32 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-04-19 13:28:32 +0000 |
commit | d7f7bac629f6a2a0ce72b81964acef4829ca9436 (patch) | |
tree | 6873b22b60c7f95629dd1e29400bc16a5f3c9453 /lib/libc | |
parent | 020b763fcf974f37f21137d931a80fd877f3d281 (diff) | |
download | FreeBSD-src-d7f7bac629f6a2a0ce72b81964acef4829ca9436.zip FreeBSD-src-d7f7bac629f6a2a0ce72b81964acef4829ca9436.tar.gz |
MFC r281082: fts: Don't return FTS_SLNONE if it's not a symlink (if race).
When following symlinks, fts returned FTS_SLNONE when fstatat(flag=0)
failed, but a subsequent fstatat(flag=AT_SYMLINK_NOFOLLOW) succeeded. This
incorrectly triggered if a filename existed to be read from the directory,
was deleted before the fstatat(flag=0) and created again after the
fstatat(flag=0).
Fix this by only returning FTS_SLNONE if the result from
fstatat(flag=AT_SYMLINK_NOFOLLOW) is actually a symlink. If it is not a
symlink, treat it as if fstatat(flag=0) succeeded.
PR: 196724
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/fts.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 7635fbc..1ca8334 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -905,12 +905,13 @@ fts_stat(FTS *sp, FTSENT *p, int follow, int dfd) if (ISSET(FTS_LOGICAL) || follow) { if (fstatat(dfd, path, sbp, 0)) { saved_errno = errno; - if (!fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) { - errno = 0; - return (FTS_SLNONE); + if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) { + p->fts_errno = saved_errno; + goto err; } - p->fts_errno = saved_errno; - goto err; + errno = 0; + if (S_ISLNK(sbp->st_mode)) + return (FTS_SLNONE); } } else if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) { p->fts_errno = errno; |