From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/5] qtest: Document calling conventions
Date: Fri, 21 Jul 2017 08:42:43 +0200 [thread overview]
Message-ID: <87379ql28s.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <9674afa4-78b3-044b-4e5f-4014888ff03e@redhat.com> (Eric Blake's message of "Thu, 20 Jul 2017 15:53:56 -0500")
Eric Blake <eblake@redhat.com> writes:
> On 07/20/2017 03:37 PM, Eric Blake wrote:
>>>> + * @fmt...: QMP message to send to qemu; only recognizes formats
>>>> + * understood by json-lexer.c
>>>> *
>>>> * Sends a QMP message to QEMU and consumes the response.
>>>> */
>>>
>>> These formats are chosen so that gcc can help us check them. Please add
>>> GCC_FMT_ATTR(). Precedence: qobject_from_jsonf().
>>
>> Will do. (This patch was originally part of my larger series trying to
>> get rid of qobject_from_jsonf() - I may still succeed at that, but
>> separating the easy stuff from the controversial means that the easy
>> stuff needs tweaking).
>
> Bleargh. It's not that simple.
>
> With printf-style, hmp("literal") and hmp("%s", "literal") produce the
> same results.
>
> But with json-lexer style, %s MODIFIES its input.
Your assertion "MODIFIES its input" confused me briefly, because I read
it as "side effect on the argument string". That would be bonkers.
What you mean is it doesn't emit the argument string unmodified.
> The original qmp("{'execute':\"foo\"}") sends a JSON object
> {'execute':"foo"}
> but counterpart qmp("%s", "{'execute':'foo'}") sends a JSON string with
> added \ escaping:
> "{'execute':\"foo\"}"
>
> So adding the format immediately causes lots of warnings, such as:
>
> CC tests/vhost-user-test.o
> tests/vhost-user-test.c: In function ‘test_migrate’:
> tests/vhost-user-test.c:668:5: error: format not a string literal and no
> format arguments [-Werror=format-security]
> rsp = qmp(cmd);
> ^~~
cmd = g_strdup_printf("{ 'execute': 'migrate',"
"'arguments': { 'uri': '%s' } }",
uri);
rsp = qmp(cmd);
g_free(cmd);
g_assert(qdict_haskey(rsp, "return"));
QDECREF(rsp);
For this to work, @uri must not contain funny characters.
Shouldn't we simply use the built-in quoting here?
rsp = qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", uri);
g_assert(qdict_haskey(rsp, "return"));
QDECREF(rsp);
>
> CC tests/boot-order-test.o
> tests/boot-order-test.c: In function ‘test_a_boot_order’:
> tests/boot-order-test.c:46:26: error: zero-length gnu_printf format
> string [-Werror=format-zero-length]
> qmp_discard_response(""); /* HACK: wait for event */
> ^~
Should use qmp_eventwait(). Doesn't because it predates it.
> but we CAN'T rewrite those to qmp("%s", command).
Got more troublemakers?
> Now you can sort-of understand why my larger series wanted to get rid of
> qobject_from_jsonf(), since our use of GCC_FMT_ATTR() there is a lie?
I don't think it's a lie. qobject_from_jsonf() satisfies the attribute
format(printf, ...) contract: it fetches varargs exactly like printf().
What it does with them is of no concern to this attribute.
next prev parent reply other threads:[~2017-07-21 6:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-14 19:08 [Qemu-devel] [PATCH 0/5] random qapi cleanups Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 1/5] qapi: Further enhance visitor virtual walk doc example Eric Blake
2017-07-20 9:05 ` Markus Armbruster
2017-07-20 20:21 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 2/5] tests: Enhance qobject output to cover partial visit Eric Blake
2017-07-20 9:52 ` Markus Armbruster
2017-07-20 20:27 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 3/5] qapi: Visitor documentation tweak Eric Blake
2017-07-20 10:00 ` Markus Armbruster
2017-07-20 20:28 ` Eric Blake
2017-07-14 19:08 ` [Qemu-devel] [PATCH 4/5] qtest: Avoid passing raw strings through hmp() Eric Blake
2017-07-20 10:03 ` Markus Armbruster
2017-07-14 19:08 ` [Qemu-devel] [PATCH 5/5] qtest: Document calling conventions Eric Blake
2017-07-20 10:10 ` Markus Armbruster
2017-07-20 20:37 ` Eric Blake
2017-07-20 20:53 ` Eric Blake
2017-07-21 6:42 ` Markus Armbruster [this message]
2017-07-21 12:08 ` Eric Blake
2017-07-21 14:13 ` Markus Armbruster
2017-07-18 16:09 ` [Qemu-devel] [PATCH 0/5] random qapi cleanups Markus Armbruster
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=87379ql28s.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.