]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
enumerator: Fall back to lstat() if stat() fails when enumerating dirs/files
authorTobias Brunner <tobias@strongswan.org>
Wed, 12 Feb 2020 16:37:34 +0000 (17:37 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 13 Feb 2020 10:54:19 +0000 (11:54 +0100)
This happens e.g. if the path is for an invalid symlink.

src/libstrongswan/collections/enumerator.c
src/libstrongswan/utils/compat/windows.h

index 21aa9f66b7165b1225c21d70dc1d11b22a2cffd1..3833d553db6a3c833374003479b5e48fd6a1ccf4 100644 (file)
@@ -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));
index 68e1dca804fb46d65663b57bb1a11d4edd96abf3..7c6992300dc9e1dd81227f5c959c1ef8454624bb 100644 (file)
@@ -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
  */