e4crypt: remove unneeded stat(2) call in do_get_policy()
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>
diff --git a/misc/e4crypt.c b/misc/e4crypt.c
index 3efbf6e..2ae6254 100644
--- a/misc/e4crypt.c
+++ b/misc/e4crypt.c
@@ -760,7 +760,6 @@
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 @@
}
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);