From: Theodore Ts'o Date: Sun, 24 Jun 2018 23:28:13 +0000 (-0400) Subject: e4crypt: remove unneeded stat(2) call in do_get_policy() X-Git-Tag: v1.44.3-rc1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10b6e089e589a3bfc2b1ee0c9aca98183e4b9b32;p=thirdparty%2Fe2fsprogs.git 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 --- diff --git a/misc/e4crypt.c b/misc/e4crypt.c index 3efbf6e63..2ae6254a2 100644 --- a/misc/e4crypt.c +++ b/misc/e4crypt.c @@ -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);