From: Eric Sandeen <sandeen@sandeen.net>
To: Eric Sandeen <sandeen@redhat.com>, xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH V2] xfs_io: test for invalid -Tr flag combination before open
Date: Thu, 27 Feb 2014 14:41:51 -0600 [thread overview]
Message-ID: <530FA30F.70805@sandeen.net> (raw)
In-Reply-To: <530F9F37.8020408@redhat.com>
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."
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
V2: New summary & commit message
diff --git a/io/open.c b/io/open.c
index 6bb0d46..c106fa7 100644
--- 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;
}
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
prev parent reply other threads:[~2014-02-27 20:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-27 20:25 [PATCH] xfs_io: don't leak fd in open -Tr failure case Eric Sandeen
2014-02-27 20:32 ` Eric Sandeen
2014-02-27 20:34 ` Christoph Hellwig
2014-02-27 20:41 ` Eric Sandeen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=530FA30F.70805@sandeen.net \
--to=sandeen@sandeen.net \
--cc=sandeen@redhat.com \
--cc=xfs@oss.sgi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox