From: Tobias Brunner Date: Wed, 12 Feb 2020 16:37:34 +0000 (+0100) Subject: enumerator: Fall back to lstat() if stat() fails when enumerating dirs/files X-Git-Tag: 5.8.3dr1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19b2f870e23f4cc4faf57a4b2379062f3cb428ec;p=thirdparty%2Fstrongswan.git enumerator: Fall back to lstat() if stat() fails when enumerating dirs/files This happens e.g. if the path is for an invalid symlink. --- diff --git a/src/libstrongswan/collections/enumerator.c b/src/libstrongswan/collections/enumerator.c index 21aa9f66b7..3833d553db 100644 --- a/src/libstrongswan/collections/enumerator.c +++ b/src/libstrongswan/collections/enumerator.c @@ -129,9 +129,10 @@ METHOD(enumerator_t, enumerate_dir_enum, bool, { *absolute = this->full; } - if (st) + if (st && stat(this->full, st)) { - if (stat(this->full, st)) + /* try lstat() e.g. if a symlink is not valid anymore */ + if ((errno != ENOENT && errno != ENOTDIR) || lstat(this->full, st)) { DBG1(DBG_LIB, "stat() on '%s' failed: %s", this->full, strerror(errno)); diff --git a/src/libstrongswan/utils/compat/windows.h b/src/libstrongswan/utils/compat/windows.h index 68e1dca804..7c6992300d 100644 --- a/src/libstrongswan/utils/compat/windows.h +++ b/src/libstrongswan/utils/compat/windows.h @@ -222,6 +222,11 @@ static inline int setenv(const char *name, const char *value, int overwrite) return 0; } +/** + * stat(2) behaves like lstat(2) for symbolic links on Windows + */ +#define lstat stat + /** * Lazy binding, ignored on Windows */