]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
security: avoid use of dirent d_type field
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 2 Apr 2019 12:35:43 +0000 (13:35 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 3 Apr 2019 10:31:38 +0000 (11:31 +0100)
The d_type field cannot be assumed to be filled. Some filesystems, such
as older XFS, will simply report DT_UNKNOWN.

Even if the d_type is filled in, the use of it in the SELinux functions
is dubious. If labelling all files in a directory there's no reason to
skip things which are not regular files. We merely need to skip "." and
"..", which is done by virDirRead() already.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/security/security_selinux.c

index 2fceb547b4f6a1bebe3e619d24b08ef6883d2c01..094272e084626d2f29c845a3a84f458fe2ee5ced 100644 (file)
@@ -3282,9 +3282,6 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr mgr,
         return -1;
 
     while ((ret = virDirRead(dir, &ent, path)) > 0) {
-        if (ent->d_type != DT_REG)
-            continue;
-
         if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) {
             ret = -1;
             break;
@@ -3334,9 +3331,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManagerPtr mgr,
         return -1;
 
     while ((ret = virDirRead(dir, &ent, path)) > 0) {
-        if (ent->d_type != DT_REG)
-            continue;
-
         if (virAsprintf(&filename, "%s/%s", path, ent->d_name) < 0) {
             ret = -1;
             break;