Whamcloud - gitweb
e4crypt: remove unneeded stat(2) call in do_get_policy()
authorTheodore Ts'o <tytso@mit.edu>
Sun, 24 Jun 2018 23:28:13 +0000 (19:28 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Jun 2018 23:28:13 +0000 (19:28 -0400)
We don't need to conditionally use O_DIRECTORY when opening a
directory.  Remove the unneeded stat, and a TOCTOU complaint from
Coverity.

Fixes-Coverity-Bug: 1293497
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e4crypt.c

index 3efbf6e..2ae6254 100644 (file)
@@ -760,7 +760,6 @@ static void do_set_policy(int argc, char **argv, const struct cmd_desc *cmd)
 static void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
 {
        struct ext4_encryption_policy policy;
-       struct stat st;
        int i, j, fd, rc;
 
        if (argc < 2) {
@@ -771,12 +770,7 @@ static void do_get_policy(int argc, char **argv, const struct cmd_desc *cmd)
        }
 
        for (i = 1; i < argc; i++) {
-               if (stat(argv[i], &st) < 0) {
-                       perror(argv[i]);
-                       continue;
-               }
-               fd = open(argv[i],
-                         S_ISDIR(st.st_mode) ? O_DIRECTORY : O_RDONLY);
+               fd = open(argv[i], O_RDONLY);
                if (fd == -1) {
                        perror(argv[i]);
                        exit(1);