From: Ján Tomko Date: Tue, 21 Jun 2016 15:23:41 +0000 (+0200) Subject: Skip '.' and '..' in virDirRead X-Git-Tag: v2.0.0-rc1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cecfba1396200490e14de1c5585aa9d5244e609;p=thirdparty%2Flibvirt.git Skip '.' and '..' in virDirRead All of the callers either skip these explicitly, skip all entries starting with a dot or match the entry name against stricter patterns. --- diff --git a/src/util/virfile.c b/src/util/virfile.c index ce8f7fd860..d6419964c9 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -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; }