Do not silently ignore files when applying them in smackload/ctl
authorJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tue, 3 Dec 2013 16:22:55 +0000 (18:22 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tue, 3 Dec 2013 16:28:39 +0000 (18:28 +0200)
Detect unknown file types and non-regular files and fail if they
are found with proper error reporting.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
utils/common.c

index deee6b1..e1439ed 100644 (file)
@@ -68,9 +68,23 @@ int apply_rules(const char *path, int clear)
        if (dir) {
                for (dfd = dirfd(dir), dent = readdir(dir);
                     dent != NULL; dent = readdir(dir)) {
-                       if (dent->d_type != DT_REG)
+                       if (dent->d_type == DT_DIR)
                                continue;
 
+                       if (dent->d_type == DT_UNKNOWN) {
+                               fprintf(stderr, "'%s' file type is unknown\n",
+                                       dent->d_name);
+                               closedir(dir);
+                               return -1;
+                       }
+
+                       if (dent->d_type != DT_REG) {
+                               fprintf(stderr, "'%s' is a non-regular file\n",
+                                       dent->d_name);
+                               closedir(dir);
+                               return -1;
+                       }
+
                        fd = openat(dfd, dent->d_name, O_RDONLY);
                        if (fd == -1) {
                                fprintf(stderr, "openat() failed for '%s' : %s\n",