udevadm: cleanup_dir: use dot_or_dot_dot()
authorMartin Wilck <mwilck@suse.com>
Fri, 21 Jan 2022 09:44:26 +0000 (10:44 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 15 Feb 2022 01:13:47 +0000 (01:13 +0000)
which is safer than just checking dent[0].
Also, fix two style issues.

(cherry picked from commit 28d6e8545151d413f8614db9fa790f9f9edbb045)
(cherry picked from commit 494e3c0def197abd4ec88f7b0c3ba331a708d81e)

src/udev/udevadm-info.c

index fa7f04f14ce8cda0721dd426fece6d2c550f2290..f05363150e7c5a1544dd7b63df574a594f0503fc 100644 (file)
@@ -224,12 +224,14 @@ static void cleanup_dir(DIR *dir, mode_t mask, int depth) {
         if (depth <= 0)
                 return;
 
+        assert(dir);
+
         FOREACH_DIRENT_ALL(dent, dir, break) {
                 struct stat stats;
 
-                if (dent->d_name[0] == '.')
+                if (dot_or_dot_dot(dent->d_name))
                         continue;
-                if (fstatat(dirfd(dir), dent->d_name, &stats, AT_SYMLINK_NOFOLLOW) != 0)
+                if (fstatat(dirfd(dir), dent->d_name, &stats, AT_SYMLINK_NOFOLLOW) < 0)
                         continue;
                 if ((stats.st_mode & mask) != 0)
                         continue;