From: Eric Blake <eblake@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, pkrempa@redhat.com
Subject: Re: [Qemu-devel] [PATCH 24/24] keyval: Support lists
Date: Tue, 28 Feb 2017 14:06:20 -0600 [thread overview]
Message-ID: <c1efb07d-e5ab-b627-8cf7-1a0c364e7c86@redhat.com> (raw)
In-Reply-To: <20170228192543.GZ4090@noname.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4052 bytes --]
On 02/28/2017 01:25 PM, Kevin Wolf wrote:
> Am 27.02.2017 um 12:20 hat Markus Armbruster geschrieben:
>> Additionally permit non-negative integers as key components. A
>> dictionary's keys must either be all integers or none. If all keys
>> are integers, convert the dictionary to a list. The set of keys must
>> be [0,N].
>>
>> @@ -34,16 +36,16 @@
>> * doesn't have one, because R.a must be an object to satisfy a.b=1
>> * and a string to satisfy a=2.
>> *
>> - * Key-fragments must be valid QAPI names.
>> + * Key-fragments must be valid QAPI names or consist only of digits.
>> /*
>> + * Convert @key to a list index.
>> + * Convert all leading digits to a (non-negative) number, capped at
>> + * INT_MAX.
>> + * If @end is non-null, assign a pointer to the first character after
>> + * the number to *@end.
>> + * Else, fail if any characters follow.
>> + * On success, return the converted number.
>> + * On failure, return a negative value.
>> + * Note: since only digits are converted, no two keys can map to the
>> + * same number, except by overflow to INT_MAX.
>> + */
>> +static int key_to_index(const char *key, const char **end)
>> +{
>> + int ret;
>> + unsigned long index;
>> +
>> + if (*key < '0' || *key > '9') {
>> + return -EINVAL;
>> + }
So no leading whitespace, '+', or '-', even if strtoul would have
allowed it. Such names are also invalid as member id names. (There's
still the question if we want to allow arbitrary whitespace after
between-key-value ',', and maybe even after between-key-segment '.'
after this series, to make it easier to write strategically line-wrapped
command lines - but that's an independent thing to be done on top).
>> @@ -137,8 +165,13 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
>> cur = qdict;
>> s = key;
>> for (;;) {
>> - ret = parse_qapi_name(s, false);
>> - len = ret < 0 ? 0 : ret;
>> + /* Want a key index (unless it's first) or a QAPI name */
>> + if (s != key && key_to_index(s, &end) >= 0) {
>> + len = end - s;
>> + } else {
>> + ret = parse_qapi_name(s, false);
>> + len = ret < 0 ? 0 : ret;
>> + }
Does this mishandle keyval_parse(string, "0", err) - where we want to
assert that the caller always passes only a valid id name for an
implicit key?
>> assert(s + len <= key_end);
>> if (!len || (s + len < key_end && s[len] != '.')) {
>> assert(key != implied_key);
>> @@ -205,6 +238,119 @@ static const char *keyval_parse_one(QDict *qdict, const char *params,
>> return s;
>> }
>>
>> +static char *reassemble_key(GSList *key)
>> +{
>> + GString *s = g_string_new("");
>> + GSList *p;
>> +
>> + for (p = key; p; p = p->next) {
>> + g_string_prepend_c(s, '.');
>> + g_string_prepend(s, (char *)p->data);
Should this use the canonical form of an index, even if the user spelled
it with extra bytes like leading zero?
>> + /* Copy @cur's values to @elt[] */
>> + nelt = qdict_size(cur);
>> + elt = g_new0(QObject *, nelt);
>
> This doesn't seem to be freed.
>
>> + for (ent = qdict_first(cur); ent; ent = qdict_next(cur, ent)) {
>> + index = key_to_index(ent->key, NULL);
>> + assert(index >= 0);
>> + /*
>> + * We iterate @nelt times. Because the dictionary keys are
>> + * distinct, the indexes are also distinct (key_to_index()
>> + * ensures it).
>
> Really? What about leading zeros?
key_to_index() should be used to convert "01" and "1" into the same key
when first computing the QDict during the initial parse; this post-pass
should thus only see a single "1" key (last-one-wins semantics,
regardless of the difference in spelling of the same index repeated on
the command line).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2017-02-28 20:06 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 11:20 [Qemu-devel] [PATCH 00/24] block: Command line option -blockdev Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 01/24] test-qemu-opts: Cover qemu_opts_parse() of "no" Markus Armbruster
2017-02-28 15:34 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 02/24] tests: Fix gcov-files-test-qemu-opts-y, gcov-files-test-logging-y Markus Armbruster
2017-02-28 15:34 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 03/24] keyval: New keyval_parse() Markus Armbruster
2017-02-28 15:48 ` Kevin Wolf
2017-02-28 16:36 ` Markus Armbruster
2017-02-28 16:57 ` Eric Blake
2017-02-28 18:03 ` Markus Armbruster
2017-02-28 18:51 ` Eric Blake
2017-02-28 19:15 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 04/24] qapi: qobject input visitor variant for use with keyval_parse() Markus Armbruster
2017-02-28 16:03 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 05/24] test-keyval: Cover use with qobject input visitor Markus Armbruster
2017-02-28 16:21 ` Kevin Wolf
2017-02-28 18:04 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 06/24] qapi: Factor out common part of qobject input visitor creation Markus Armbruster
2017-02-28 16:24 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 07/24] qapi: Factor out common qobject_input_get_keyval() Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 08/24] qobject: Propagate parse errors through qobject_from_jsonv() Markus Armbruster
2017-02-28 16:32 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 09/24] libqtest: Fix qmp() & friends to abort on JSON parse errors Markus Armbruster
2017-02-28 16:51 ` Kevin Wolf
2017-02-28 18:05 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 10/24] qjson: Abort earlier on qobject_from_jsonf() misuse Markus Armbruster
2017-02-28 16:51 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 11/24] test-qobject-input-visitor: Abort earlier on bad test input Markus Armbruster
2017-02-28 16:52 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 12/24] qobject: Propagate parse errors through qobject_from_json() Markus Armbruster
2017-02-28 16:55 ` Kevin Wolf
2017-02-28 19:19 ` Eric Blake
2017-02-28 19:48 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 13/24] block: More detailed syntax error reporting for JSON filenames Markus Armbruster
2017-02-28 16:58 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 14/24] check-qjson: Test errors from qobject_from_json() Markus Armbruster
2017-02-28 17:06 ` Kevin Wolf
2017-02-28 19:25 ` Eric Blake
2017-02-28 19:52 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 15/24] test-visitor-serialization: Pass &error_abort to qobject_from_json() Markus Armbruster
2017-02-28 17:09 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 16/24] monitor: Assert qmp_schema_json[] is sane Markus Armbruster
2017-02-28 17:11 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 17/24] qapi: New qobject_input_visitor_new_str() for convenience Markus Armbruster
2017-02-28 17:18 ` Kevin Wolf
2017-02-28 18:48 ` Markus Armbruster
2017-02-28 19:29 ` Kevin Wolf
2017-02-28 17:33 ` Kevin Wolf
2017-02-28 18:45 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 18/24] block: Initial implementation of -blockdev Markus Armbruster
2017-02-28 19:38 ` Eric Blake
2017-02-28 19:57 ` Kevin Wolf
2017-02-28 20:59 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 19/24] qapi: Improve how keyval input visitor reports unexpected dicts Markus Armbruster
2017-02-28 17:51 ` Kevin Wolf
2017-02-28 18:52 ` Markus Armbruster
2017-02-27 11:20 ` [Qemu-devel] [PATCH 20/24] docs/qapi-code-gen.txt: Clarify naming rules Markus Armbruster
2017-02-28 17:54 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 21/24] test-qapi-util: New, covering qapi/qapi-util.c Markus Armbruster
2017-02-28 17:57 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 22/24] qapi: New parse_qapi_name() Markus Armbruster
2017-02-28 18:02 ` Kevin Wolf
2017-02-28 18:54 ` Markus Armbruster
2017-02-28 19:48 ` Eric Blake
2017-02-27 11:20 ` [Qemu-devel] [PATCH 23/24] keyval: Restrict key components to valid QAPI names Markus Armbruster
2017-02-28 18:06 ` Kevin Wolf
2017-02-27 11:20 ` [Qemu-devel] [PATCH 24/24] keyval: Support lists Markus Armbruster
2017-02-28 19:25 ` Kevin Wolf
2017-02-28 19:58 ` Markus Armbruster
2017-02-28 20:06 ` Eric Blake [this message]
2017-02-28 21:04 ` Markus Armbruster
2017-02-28 16:25 ` [Qemu-devel] [PATCH 00/24] block: Command line option -blockdev Eric Blake
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=c1efb07d-e5ab-b627-8cf7-1a0c364e7c86@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=pkrempa@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).