qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [PATCH] iotests: Quote $cmd in _send_qemu_cmd
Date: Tue, 15 Dec 2020 16:49:33 +0100	[thread overview]
Message-ID: <20201215154933.GG8185@merkur.fritz.box> (raw)
In-Reply-To: <61dede63-7561-88a7-312e-ec5babf667a1@redhat.com>

Am 15.12.2020 um 13:14 hat Max Reitz geschrieben:
> On 15.12.20 12:43, Kevin Wolf wrote:
> > Am 14.12.2020 um 18:58 hat Max Reitz geschrieben:
> > > With bash 5.1, the output of the following script (which creates an
> > > array with a single element, then takes a single-element slice from that
> > > array, and echos the result) changes:
> > > 
> > >    a=("double  space")
> > >    a=${a[@]:0:1}
> > >    echo "$a"
> > > 
> > > from "double space" to "double  space", i.e. all white space is
> > > preserved as-is.  This is probably what we actually want here (judging
> > > from the "...to accommodate pathnames with spaces" comment), but before
> > > 5.1, we have to quote the ${} slice to get the same behavior.
> > > 
> > > In any case, without quoting, the reference output of many iotests is
> > > different between bash 5.1 and pre-5.1, which is not very good.  We
> > > should fix it by quoting here, and then adjusting all the reference
> > > output of all iotests using _send_qemu_cmd accordingly.  (The only
> > > ones we do not need to change are those that do not have multiple
> > > consecutive whitespaces in their _send_qemu_cmd parameters.)
> > > 
> > > Signed-off-by: Max Reitz <mreitz@redhat.com>
> > > ---
> > > Alternatively, we could explicitly collapse all whitespace sequences
> > > into single spaces, but I believe that would defeat the purpose of
> > > "accomodat[ing] pathnames with spaces".
> > 
> > I agree that quoting is the better alternative.
> > 
> > The whole thing shouldn't be needed if callers propertly quote
> > filenames. If I understand correctly, these lines just try to merge
> > back filenames that have been split into multiple words because the
> > caller wasn't careful. But we can't reliably do that because we don't
> > know which and how much whitespace was removed.
> 
> No, without quoting here, the slice operation will actually collapse spaces
> inside of array elements, as shown in the commit message
> (a=("x  y") creates an array with a single element that just has two spaces
> in it).  If the caller didn’t quote, then quoting in _send_qemu_cmd wouldn’t
> help either, because the whitespace would no longer be present in $@.

This is exactly what I mean. The whole slicing seems to be an attempt at
reconstructing an original unquoted string, which can't work because you
can't reconstruct the right whitespace.

So if it can't work anyway, we probably shouldn't even attempt to and
just use a single parameter instead of an array slice and require
callers to do proper quoting...

> Most callers of _send_qemu_cmd actually do something like this:
> 
> _send_qemu_cmd \
>     $QEMU_HANDLE \
>     "{ 'execute': 'something',
>        'arguments': ... }" \
>     'return'
> 
> So they do quote all of their arguments, and actually only pass three (or
> four, with success_or_failure=y), so basically the slicing is generally
> unnecessary and we’d just need cmd=$1 (not $2, because _send_qemu_cmd likes
> to invoke “shift”).

...which they apparently already do.

> In fact, if you do that on top of this patch (cmd=$1 instead of the fancy
> slice), you’ll see that the only test that then doesn’t pass is 102.  I
> think that’s because it has this one _send_qemu_cmd invocation that forgot
> to pass $QEMU_HANDLE...?
> 
> So, alternatively to quoting the slice, we could also just set cmd=$1 and
> fix 102.

Ah, looks like you don't even need to quote it like cmd="$1"? Maybe I
should learn bash sometime...

But yes, this is what I was thinking of.

Kevin



  reply	other threads:[~2020-12-15 15:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 17:58 [PATCH] iotests: Quote $cmd in _send_qemu_cmd Max Reitz
2020-12-15 11:43 ` Kevin Wolf
2020-12-15 12:14   ` Max Reitz
2020-12-15 15:49     ` Kevin Wolf [this message]
2020-12-15 15:58       ` Max Reitz

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=20201215154933.GG8185@merkur.fritz.box \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).