From: Stefan Hajnoczi <stefanha@gmail.com>
To: Eric Blake <eblake@redhat.com>
Cc: River Chiang <riverchiang@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Prevent overriding the input file with the output file when using qemu-img
Date: Thu, 25 Jan 2018 10:52:57 +0000 [thread overview]
Message-ID: <20180125105257.GC27269@stefanha-x1.localdomain> (raw)
In-Reply-To: <982e13e4-6591-0f4c-9faa-17e0302ad350@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]
On Tue, Jan 23, 2018 at 08:48:15AM -0600, Eric Blake wrote:
> On 01/22/2018 10:40 PM, River Chiang wrote:
> > Signed-off-by: River Chiang <riverchiang@gmail.com>
> >
> > ---------------------------------- qemu-img.c
> > ----------------------------------
> > index 68b375f998..5ce594ea00 100644
> > @@ -2098,6 +2098,9 @@ static int img_convert(int argc, char **argv)
> > if (s.src_num < 1) {
> > error_report("Must specify image file name");
> > goto fail_getopt;
> > + } else if (!strcmp(argv[optind], out_filename)) {
> > + error_report("Override the input file with the output file");
> > + goto fail_getopt;
>
> Comparing names is too prone to false negatives. 'foo' and './foo' are
> the same file, but your test won't catch it. Better might be checking
> if stat() reports the same dev/inode pair for the two files.
>
> By the way, your patch is not in proper 'git send-email' format, which
> makes it hard to test whether it even applies. More patch submission
> hints at http://wiki.qemu.org/Contribute/SubmitAPatch
stat(2) cannot be used since the "filenames" may not be a local file,
(nbd://, iscsi://, etc).
strcmp(3) is also not a full solution, for the reasons you mentioned.
Even file locking probably isn't a full solution. What happens when
input and output files are nbd:// URIs?
Attempting to prevent the user from harming themselves is very hard to
do. It's better not to second-guess the user than to have some magic
that doesn't always work (the user cannot rely on it anyway).
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2018-01-25 10:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-23 4:40 [Qemu-devel] Prevent overriding the input file with the output file when using qemu-img River Chiang
2018-01-23 14:48 ` Eric Blake
2018-01-23 15:26 ` Eric Blake
2018-01-25 10:52 ` Stefan Hajnoczi [this message]
2018-01-25 11:02 ` Daniel P. Berrangé
2018-01-29 13:49 ` Stefan Hajnoczi
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=20180125105257.GC27269@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=riverchiang@gmail.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;
as well as URLs for NNTP newsgroup(s).