]> xenbits.xensource.com Git - libvirt.git/commitdiff
Skip '.' and '..' in virDirRead
authorJán Tomko <jtomko@redhat.com>
Tue, 21 Jun 2016 15:23:41 +0000 (17:23 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 23 Jun 2016 19:58:38 +0000 (21:58 +0200)
All of the callers either skip these explicitly, skip all entries
starting with a dot or match the entry name against stricter patterns.

src/util/virfile.c

index ce8f7fd860b5707ccf03195a54bfee4ae060233c..d6419964c9fa09448e6ae6645a97f5b3ee7025dc 100644 (file)
@@ -2758,14 +2758,17 @@ virFileRemove(const char *path,
  */
 int virDirRead(DIR *dirp, struct dirent **ent, const char *name)
 {
-    errno = 0;
-    *ent = readdir(dirp); /* exempt from syntax-check */
-    if (!*ent && errno) {
-        if (name)
-            virReportSystemError(errno, _("Unable to read directory '%s'"),
-                                 name);
-        return -1;
-    }
+    do {
+        errno = 0;
+        *ent = readdir(dirp); /* exempt from syntax-check */
+        if (!*ent && errno) {
+            if (name)
+                virReportSystemError(errno, _("Unable to read directory '%s'"),
+                                     name);
+            return -1;
+        }
+    } while (*ent && (STREQ((*ent)->d_name, ".") ||
+                      STREQ((*ent)->d_name, "..")));
     return !!*ent;
 }