From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: libvir-list@redhat.com, Peter Maydell <peter.maydell@linaro.org>,
John Snow <jsnow@redhat.com>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: A brief look at deprecating our JSON extensions over RFC 8259
Date: Mon, 22 Feb 2021 15:24:35 +0000 [thread overview]
Message-ID: <YDPMs1Hu8LDRJUhX@redhat.com> (raw)
In-Reply-To: <875z2knoa5.fsf@dusky.pond.sub.org>
On Mon, Feb 22, 2021 at 03:57:22PM +0100, Markus Armbruster wrote:
> We use JSON in several external interfaces:
>
> * QMP
>
> * The guest agent's QMP
>
> * QAPIfied command line options when the option argument starts with
> '{'
>
> * The block layer's pseudo-protocol "json:" (which can get embedded in
> image headers)
>
> I *think* that's all.
>
> The JSON parser we use for these interfaces supports extensions over RFC
> 8259. Quoting json-lexer.c:
>
> - Extra escape sequence in strings:
> 0x27 (apostrophe) is recognized after escape, too
>
> - Single-quoted strings:
> Like double-quoted strings, except they're delimited by %x27
> (apostrophe) instead of %x22 (quotation mark), and can't contain
> unescaped apostrophe, but can contain unescaped quotation mark.
>
> - Interpolation, if enabled:
> The lexer accepts %[A-Za-z0-9]*, and leaves rejecting invalid
> ones to the parser.
>
> Ignore interpolation; it's never enabled at external interfaces.
>
> This leaves single-quotes strings and the escape sequence to go with
> them.
>
> I disabled them as an experiment. Some 20 iotests, a qtest and two unit
> tests explode.
>
> The unit test testing the JSON parser is of course excused.
>
> The remaining qtest and the unit test could perhaps be dismissed as
> atypical use of QEMU from C. The iotests less so, I think.
>
> I looked at some iotest failures, and quickly found single-quoted
> strings used with all external interfaces except for qemu-ga's QMP.
>
> We could certainly tidy up the tests to stick to standard JSON.
> However, the prevalence of single-quoted strings in iotests makes me
> suspect that they are being used in the field as well. Deprecating the
> extension is likely more trouble than it's worth.
The shell based iotests use single quotes primarily because they're
being written in a language which lacks the concept of libraries and
and so all JSON is constructed by string substitution. Using single
quotes is convenient to avoid continually escaping double quotes.
For any other language constructing JSON documents through string
substitution is insanity, because they all have JSON libraries
available which let you construct JSON documents progamatically
without risk of introducing security flaws through malicious
substitutions.
This problem isn't unique to QEMU. Any app using JSON from the
shell will have the tedium of quote escaping. JSON is incredibly
widespread and no other apps felt it neccessary to introduce single
quoting support, because the benefit doesn't outweigh the interop
problem it introduces.
> Opinions?
IMHO we should deprecate and eventually remove single quotes. We
should expect mgmt apps to be using a JSON library to talk to QEMU
in general if they are using QMP. Sure some may be using shell, but
I'd expect that to be relatively few. Adapting is tedious but not
especially hard.
It would be nice at some point in future to have the option of using
a standard JSON library in part or all of QEMU. Especially if we
ever want to be able to have parts of QEMU written in non-C language,
we don't want to re-invent a custom JSON parser as the first step,
for back compatibility.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2021-02-22 15:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-22 14:57 A brief look at deprecating our JSON extensions over RFC 8259 Markus Armbruster
2021-02-22 15:10 ` Peter Krempa
2021-02-22 15:24 ` Daniel P. Berrangé [this message]
2021-02-22 15:43 ` Liviu Ionescu
2021-02-22 17:47 ` Paolo Bonzini
2021-02-22 17:54 ` Daniel P. Berrangé
2021-02-22 18:06 ` Paolo Bonzini
2021-02-23 9:31 ` Markus Armbruster
2021-02-23 9:37 ` Markus Armbruster
2021-02-23 11:03 ` Peter Maydell
2021-02-23 12:43 ` Markus Armbruster
2021-02-23 9:06 ` Markus Armbruster
2021-02-23 10:59 ` Paolo Bonzini
2021-02-23 12:34 ` Markus Armbruster
2021-02-22 17:42 ` Paolo Bonzini
2021-02-22 18:01 ` Daniel P. Berrangé
2021-02-22 18:22 ` Peter Krempa
2021-02-22 18:25 ` Peter Krempa
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=YDPMs1Hu8LDRJUhX@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=libvir-list@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.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).