From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 4/9] tests: Clean up string interpolation into QMP input (simple cases)
Date: Fri, 21 Jul 2017 18:48:06 +0200 [thread overview]
Message-ID: <87tw25ag8p.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <295a3dcc-5165-cc23-26a2-ffb4d8ccb144@redhat.com> (Eric Blake's message of "Fri, 21 Jul 2017 09:39:23 -0500")
Eric Blake <eblake@redhat.com> writes:
> On 07/21/2017 08:53 AM, Markus Armbruster wrote:
>> When you build QMP input manually like this
>>
>> cmd = g_strdup_printf("{ 'execute': 'migrate',"
>> "'arguments': { 'uri': '%s' } }",
>> uri);
>> rsp = qmp(cmd);
>> g_free(cmd);
>>
>> you're responsible for escaping the interpolated values for JSON. Not
>> done here, and therefore works only for sufficiently nice @uri. For
>> instance, if @uri contained a single "'", qobject_from_jsonv() would
>> fail, qmp_fd_sendv() would misinterpret the failure as empty input and
>> do nothing, and the test would hang waiting for a response that never
>> comes.
>>
>> Leaving interpolation into JSON to qmp() is more robust:
>>
>> rsp = qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", uri);
>>
>> It's also more concise.
>>
>> Clean up the simple cases where we interpolate exactly a JSON value.
>>
>> Bonus: gets rid of non-literal format strings. A step towards
>> compile-time format string checking without triggering
>> -Wformat-nonliteral.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
>> ---
>> + qmp_fd_send(fixture->fd,
>> + "\xff{'execute': 'guest-sync-delimited',"
>> + " 'arguments': {'id': %u } }",
>
> Ouch. Per 2/9:
> * json-lexer.c (only understands '%((l|ll|I64)?d|[ipsf])').
>
> That will need to be %d now. Or, more likely, we need to update the
> comments in json-lexer.c and in 2/9 (/me goes to read json-lexer.c...)
> /* escape */
> [IN_ESCAPE_LL] = {
> ['d'] = JSON_ESCAPE,
> ['u'] = JSON_ESCAPE,
> },
> ...
> [IN_ESCAPE] = {
> ['d'] = JSON_ESCAPE,
> ['i'] = JSON_ESCAPE,
> ['p'] = JSON_ESCAPE,
> ['s'] = JSON_ESCAPE,
> ['u'] = JSON_ESCAPE,
> ['f'] = JSON_ESCAPE,
> ['l'] = IN_ESCAPE_L,
> ['I'] = IN_ESCAPE_I,
>
> Aha, that 'd' should be '[du]' in all of the comments.
Yes. We really need %u, or else parse_escape() would call
qnum_from_int() instead of qnum_from_uint().
I think the doc fix for json-lexer.c can be squashed in. Keeping it
separate could simplify commit message writing, though. Your choice.
>> @@ -411,10 +408,10 @@ static void test_qga_file_ops(gconstpointer fix)
>>
>> enc = g_base64_encode(helloworld, sizeof(helloworld));
>> /* write */
>> - cmd = g_strdup_printf("{'execute': 'guest-file-write',"
>> - " 'arguments': { 'handle': %" PRId64 ","
>> - " 'buf-b64': '%s' } }", id, enc);
>> - ret = qmp_fd(fixture->fd, cmd);
>> + ret = qmp_fd(fixture->fd,
>> + "{'execute': 'guest-file-write',"
>> + " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }",
>
> Ouch; you are reverting commit 1792d7d0. We tried hard to make
> json-lexer.c understand lots of different 64-bit format spellings, but
> we KNOW that we don't support MacOS (see commit 29a6731). We either
> need to beef up json-lexer.c to understand %qd, or get rid of JSON
> psuedo-strings, if we expect this to work; otherwise, you should use
> %lld and long long instead of PRId64 and uint64_t.
I forgot that PRId64 expands into non-standard crap on some systems.
Options:
1. Outlaw use of PRI macros, limit integer length modifiers for
conversion specifiers "d" and "u" to "l" and "ll". When PRI macros
creep in, the build breaks on hosts where they expand to anything
else (hopefully, our CI will catch that). Interpolating int64_t
values become a bit awkward.
Required work: fix my patches not to use PRId64, drop support for
length modifier "I64" from parse_escape().
2. Support PRId64 and PRIu64, whatever their actual value may be.
a. Support all possible values. This is what we've tried before.
Nasty: fails only at run-time on hosts with sufficiently creative
values.
Required work: add support for length modifier "q", to unbreak
MacOS.
Optional work: try to turn the run-time failure into a compile-
time failure, ideally in configure.
b. Support exactly the host's PRId64 and PRIu64 values.
Work required: replace support of "I64d" and "I64u" by support of
PRId64 and PRIu64. Easy enough in parse_escape(), but not in
json-lexer.c. We could perhaps have the lexer accept the shortest
string that's followed by a conversion specifier as length
modifier, then reject invalid length modifiers in a semantic
action.
Optional work: try to simplify code that currently works around
unavailability of PRId64 and PRIu64.
Preferences?
I like 2b, but I'm not sure I'll like the code implementing it. One way
to find out...
> Overall, I like the patch, but we need to fix the problems for the next
> round of this series.
Yes.
next prev parent reply other threads:[~2017-07-21 16:48 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 13:53 [Qemu-devel] [PATCH 0/9] tests: Clean up around qmp() and hmp() Markus Armbruster
2017-07-21 13:53 ` [Qemu-devel] [PATCH 1/9] qtest: Avoid passing raw strings through hmp() Markus Armbruster
2017-07-25 13:56 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 2/9] qtest: Document calling conventions Markus Armbruster
2017-07-21 14:24 ` Eric Blake
2017-07-21 15:48 ` Markus Armbruster
2017-07-25 13:57 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 3/9] tests: Pass literal format strings directly to qmp_FOO() Markus Armbruster
2017-07-21 14:26 ` Eric Blake
2017-07-25 13:57 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 4/9] tests: Clean up string interpolation into QMP input (simple cases) Markus Armbruster
2017-07-21 14:39 ` Eric Blake
2017-07-21 16:48 ` Markus Armbruster [this message]
2017-07-21 20:08 ` Eric Blake
2017-07-21 21:15 ` Eric Blake
2017-07-24 8:30 ` Markus Armbruster
2017-07-21 13:53 ` [Qemu-devel] [PATCH 5/9] tests/libqos/usb: Clean up string interpolation into QMP input Markus Armbruster
2017-07-21 14:50 ` Eric Blake
2017-07-21 16:49 ` Markus Armbruster
2017-07-25 14:02 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 6/9] tests/libqos/pci: " Markus Armbruster
2017-07-21 15:00 ` Eric Blake
2017-07-21 16:50 ` Markus Armbruster
2017-07-25 14:06 ` Stefan Hajnoczi
2017-07-25 14:10 ` Eric Blake
2017-07-27 8:31 ` Markus Armbruster
2017-07-21 13:53 ` [Qemu-devel] [PATCH 7/9] tests: Clean up wait for event Markus Armbruster
2017-07-21 15:02 ` Eric Blake
2017-07-25 14:08 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 8/9] tests/libqtest: Clean up how we read the QMP greeting Markus Armbruster
2017-07-21 15:02 ` Eric Blake
2017-07-25 14:08 ` Stefan Hajnoczi
2017-07-21 13:53 ` [Qemu-devel] [PATCH 9/9] tests/libqtest: Enable compile-time format string checking Markus Armbruster
2017-07-21 15:04 ` Eric Blake
2017-07-27 8:36 ` Markus Armbruster
2017-07-25 14:09 ` 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=87tw25ag8p.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=eblake@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.