From: Paolo Bonzini <pbonzini@redhat.com>
To: Amos Kong <akong@redhat.com>
Cc: qemu-devel@nongnu.org, stefanha@redhat.com, afaerber@suse.de
Subject: Re: [Qemu-devel] [PATCH] libqtest: escape strings in QMP commands, fix leak
Date: Wed, 18 Jun 2014 11:56:53 +0200 [thread overview]
Message-ID: <53A16265.9010500@redhat.com> (raw)
In-Reply-To: <20140618074158.GD18929@z.redhat.com>
Il 18/06/2014 09:41, Amos Kong ha scritto:
> - Fixed Andreas's mail address
>
> On Fri, Jun 13, 2014 at 10:15:00AM +0200, Paolo Bonzini wrote:
>> libqtest is using g_strdup_printf to format QMP commands, but
>> this does not work if the argument strings need to be escaped.
>> Instead, use the fancy %-formatting functionality of QObject.
>> The only change required in tests is that strings have to be
>> formatted as %s, not '%s' or \"%s\". Luckily this usage of
>> parameterized QMP commands is not that frequent.
>
> I got this error when I apply this patch (it works without this
> patch):
>
> {"error": {"class": "GenericError", "desc": "Parameter 'id' expects an identifier"}}
>
> Code:
> | QDict *response;
> | int i, j;
> |
> | /* start with no network/block device, slots 3 to 0x1f are free */
> | qtest_start("-net none");
> |
> | for (i = 3; i <= 0x1f; i++) {
> | for (j = 7; j >= 0; j--) {
> | response = qmp("{ 'execute': 'blockdev-add',"
> | " 'arguments': {"
> | " 'options': {"
> | " 'driver': 'file',"
> | " 'filename': '/dev/null',"
> | " 'id': 'drv-%x.%x'"
> ^^^^^^^^^
> | "} } }", i, j);
> | g_assert(response);
> | g_assert(!qdict_haskey(response, "error"));
> | QDECREF(response);
>
>
>
> Then I have to fix it by :
>
> /* start with no network/block device, slots 3 to 0x1f are free */
> qtest_start("-net none");
>
> for (i = 3; i <= 0x1f; i++) {
> for (j = 7; j >= 0; j--) {
> + sprintf(drive_id, "drv-%x.%x", i, j);
> response = qmp("{ 'execute': 'blockdev-add',"
> " 'arguments': {"
> " 'options': {"
> " 'driver': 'file',"
> " 'filename': '/dev/null',"
> - " 'id': 'drv-%x.%x'"
> - "} } }", i, j);
> + " 'id': %s"
> + "} } }", drive_id);
>
>
> Is it the expected result?
>
>
> Thanks, Amos
Thanks Amos. This is the right fix.
Paolo
next prev parent reply other threads:[~2014-06-18 9:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-13 8:15 [Qemu-devel] [PATCH] libqtest: escape strings in QMP commands, fix leak Paolo Bonzini
2014-06-18 4:06 ` Stefan Hajnoczi
2014-06-18 7:41 ` Amos Kong
2014-06-18 9:56 ` Paolo Bonzini [this message]
2014-06-25 1:06 ` Amos Kong
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=53A16265.9010500@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=akong@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).