]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: test for invalid -Tr flag combination before open
authorEric Sandeen <sandeen@sandeen.net>
Mon, 3 Mar 2014 01:29:32 +0000 (12:29 +1100)
committerDave Chinner <david@fromorbit.com>
Mon, 3 Mar 2014 01:29:32 +0000 (12:29 +1100)
Coverity spotted this.

It complained that we didn't close the fd before returning in
the error case of incompatible options, but in reality, we wouldn't
have gotten that far because open(O_RDONLY|O_TMPFILE) would be
rejected with EINVAL.

So the error handling test would never actually be true.

Fix this by moving the error checking prior to the open so
the user gets a more useful error message than "Invalid Argument."

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/open.c

index 6bb0d466c741aebae3441db1a92e87cad1fbf2a8..c106fa7d404352d29bc08caa20f2fb74fdac88c4 100644 (file)
--- a/io/open.c
+++ b/io/open.c
@@ -342,6 +342,11 @@ open_f(
        if (optind != argc - 1)
                return command_usage(&open_cmd);
 
+       if ((flags & (IO_READONLY|IO_TMPFILE)) == (IO_READONLY|IO_TMPFILE)) {
+               fprintf(stderr, _("-T and -r options are incompatible\n"));
+               return -1;
+       }
+
        fd = openfile(argv[optind], &geometry, flags, mode);
        if (fd < 0)
                return 0;
@@ -349,11 +354,6 @@ open_f(
        if (!platform_test_xfs_fd(fd))
                flags |= IO_FOREIGN;
 
-       if ((flags & (IO_READONLY|IO_TMPFILE)) == (IO_READONLY|IO_TMPFILE)) {
-               fprintf(stderr, _("-T and -r options are incompatible\n"));
-               return -1;
-       }
-
        addfile(argv[optind], fd, &geometry, flags);
        return 0;
 }