From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Fam Zheng <famz@redhat.com>,
qemu-devel@nongnu.org, wenchaoqemu@gmail.com,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass
Date: Mon, 29 Sep 2014 08:33:13 -0600 [thread overview]
Message-ID: <54296DA9.2030801@redhat.com> (raw)
In-Reply-To: <87tx3qstww.fsf@blackfin.pond.sub.org>
[-- Attachment #1: Type: text/plain, Size: 5302 bytes --]
On 09/29/2014 02:38 AM, Markus Armbruster wrote:
> Eric Blake <eblake@redhat.com> writes:
>
>> Now that we have a way to validate every type, we can also be
>> stricter about enforcing that callers that want to bypass
>> type safety in generated code. Prior to this patch, it didn't
>> matter what value was associated with the key 'gen', but it
>> looked odd that 'gen':'yes' could result in bypassing the
>> generated code. These changes also enforce the changes made
>> earlier in the series for documentation and consolidation of
>> using '**' as the wildcard type.
>
> Perhaps it's worth mentioning that the schema has always used 'gen':
> 'no'.
>
> That said, 'no' is silly. The natural JSON for a flag is false / true!
> Since you're touching it anyway, consider making it an optional boolean
> defaulting to false. Same for the other silly 'no': success-response.
I'd love to, except that the .json parser does not yet allow literal
true/false JSON keywords. Fam had a patch back in May that would fix
that; maybe I'll fold in his patch to my v5 as a prereq patch:
https://lists.gnu.org/archive/html/qemu-devel/2014-05/msg03916.html
>> @@ -256,13 +256,13 @@ def discriminator_find_enum_define(expr):
>> return find_enum(discriminator_type)
>>
>> def check_type(expr_info, source, data, allow_array = False,
>> - allowed_names = [], allow_dict = True):
>> + allowed_names = [], allow_dict = True, allow_star = False):
>> global all_types
>>
>> if data is None:
>> return
>>
>> - if data == '**':
>> + if allow_star and data == '**':
>> return
[1]
>>
>> # Check if array type for data is okay
>> @@ -278,6 +278,10 @@ def check_type(expr_info, source, data, allow_array = False,
>>
>> # Check if type name for data is okay
>> if isinstance(data, basestring):
>> + if data == '**':
>> + raise QAPIExprError(expr_info,
>> + "%s uses '**' but did not request 'gen':'no'"
>> + % source)
>> if not data in all_types:
>> raise QAPIExprError(expr_info,
>> "%s references unknown type '%s'"
>
> I'm blind: I can't see where this error gets suppressed when we have
> 'gen': 'no'.
'gen':'no' triggers the caller to pass allow_star=True to check_type
[2]; then at point [1] we short-circuit and exit if '**' was passed.
Therefore, if we get here and still have '**', then allow_star is still
false, which means 'gen':'no' was not passed and it is user error.
>
>> @@ -299,24 +303,27 @@ def check_type(expr_info, source, data, allow_array = False,
>> check_type(expr_info, "member '%s' of %s" % (key, source), value,
>> allow_array=True,
>> allowed_names=['built-in', 'union', 'struct', 'enum'],
>> - allow_dict=True)
>> + allow_dict=True, allow_star=allow_star)
>>
>
> allow_star applies recursively. Correct, because...
>
>> def check_command(expr, expr_info):
>> global commands
>> name = expr['command']
>> + allow_star = expr.has_key('gen')
>> +
[2] The other trick to note here is that this only checks if 'gen' is a
key; but at [3], which is run earlier, we further required that 'gen'
can only appear if it has value 'no'.
>> if name in commands:
>> raise QAPIExprError(expr_info,
>> "command '%s' is already defined" % name)
>> commands.append(name)
>> check_type(expr_info, "'data' for command '%s'" % name,
>> expr.get('data'), allow_array=True,
>> - allowed_names=['union', 'struct'])
>> + allowed_names=['union', 'struct'], allow_star=allow_star)
>> check_type(expr_info, "'base' for command '%s'" % name,
>> expr.get('base'), allowed_names=['struct'],
>> allow_dict=False)
>> check_type(expr_info, "'returns' for command '%s'" % name,
>> expr.get('returns'), allow_array=True,
>> - allowed_names=['built-in', 'union', 'struct', 'enum'])
>> + allowed_names=['built-in', 'union', 'struct', 'enum'],
>> + allow_star=allow_star)
>>
>
> ... it applies exactly to a command's 'data' and 'returns' when it has
> 'gen': 'no'. Good.
>
>> def check_event(expr, expr_info):
>> global events
>> @@ -450,6 +457,10 @@ def check_keys(expr_elem, meta, required, optional=[]):
>> raise QAPIExprError(info,
>> "%s '%s' has unknown key '%s'"
>> % (meta, name, key))
>> + if (key == 'gen' or key == 'success-response') and value != 'no':
>> + raise QAPIExprError(info,
>> + "'%s' of %s '%s' should only have value 'no'"
>> + % (key, meta, name))
[3]
>> for key in required:
>> if not expr.has_key(key):
>> raise QAPIExprError(info,
> [...]
>
>
--
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: 539 bytes --]
next prev parent reply other threads:[~2014-09-29 14:33 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-19 22:24 [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 01/19] qapi: Consistent whitespace in tests/Makefile Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 02/19] qapi: Ignore files created during make check Eric Blake
2014-09-23 8:07 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 03/19] qapi: Update docs given recent event, spacing fixes Eric Blake
2014-09-22 12:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 04/19] qapi: Document type-safety considerations Eric Blake
2014-09-22 12:37 ` Markus Armbruster
2014-09-22 16:53 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 05/19] qapi: Add some enum tests Eric Blake
2014-09-22 12:43 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 06/19] qapi: Better error messages for bad enums Eric Blake
2014-09-23 14:23 ` Markus Armbruster
2014-09-23 15:59 ` Eric Blake
2014-09-24 7:46 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 07/19] qapi: Add some expr tests Eric Blake
2014-09-23 14:26 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 08/19] qapi: Better error messages for bad expressions Eric Blake
2014-09-23 14:56 ` Markus Armbruster
2014-09-23 16:11 ` Eric Blake
2014-09-24 7:34 ` Markus Armbruster
2014-09-24 9:25 ` Kevin Wolf
2014-09-24 11:14 ` Markus Armbruster
2014-09-26 9:15 ` Markus Armbruster
2014-09-26 9:25 ` Kevin Wolf
2014-09-26 11:40 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 09/19] qapi: Add tests of redefined expressions Eric Blake
2014-09-24 11:24 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 10/19] qapi: Better error messages for duplicated expressions Eric Blake
2014-09-24 11:58 ` Markus Armbruster
2014-09-24 14:10 ` Eric Blake
2014-09-24 15:29 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 11/19] qapi: Add tests of type bypass Eric Blake
2014-09-24 16:10 ` Markus Armbruster
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 7:34 ` Markus Armbruster
2014-09-25 8:06 ` Markus Armbruster
2014-09-25 14:00 ` Eric Blake
2014-09-25 16:19 ` Markus Armbruster
2015-03-23 15:33 ` [Qemu-devel] RFC: 'alternate' qapi top-level expression [was: [PATCH v4 12/19] qapi: Add some type check tests] Eric Blake
2015-03-23 19:28 ` Markus Armbruster
2014-09-25 13:54 ` [Qemu-devel] [PATCH v4 12/19] qapi: Add some type check tests Eric Blake
2014-09-25 16:12 ` Markus Armbruster
2014-09-25 16:32 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 13/19] qapi: More rigourous checking of types Eric Blake
2014-09-26 9:26 ` Markus Armbruster
2014-09-29 8:27 ` Markus Armbruster
2014-09-29 14:26 ` Eric Blake
2014-09-29 14:35 ` Eric Blake
2014-09-19 22:24 ` [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass Eric Blake
2014-09-29 8:38 ` Markus Armbruster
2014-09-29 14:33 ` Eric Blake [this message]
2014-09-29 16:35 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 15/19] qapi: Merge UserDefTwo and UserDefNested in tests Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 16/19] qapi: Drop tests for inline subtypes Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 17/19] qapi: Drop inline subtype in query-version Eric Blake
2014-09-30 17:40 ` Markus Armbruster
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 18/19] qapi: Drop inline subtype in query-pci Eric Blake
2014-09-19 22:25 ` [Qemu-devel] [PATCH v4 19/19] qapi: Drop support for inline subtypes Eric Blake
2014-09-30 17:47 ` Markus Armbruster
2014-09-26 15:42 ` [Qemu-devel] [PATCH v4 00/19] drop qapi nested structs 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=54296DA9.2030801@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wenchaoqemu@gmail.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 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.