Received: from eggs.gnu.org ([2001:4830:134:3::10]:48686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYdvM-0001If-IY for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:35:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYdvH-0002YG-Df for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:35:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYdvH-0002XR-6W for qemu-devel@nongnu.org; Mon, 29 Sep 2014 12:35:39 -0400 From: Markus Armbruster References: <1411165504-18198-1-git-send-email-eblake@redhat.com> <1411165504-18198-15-git-send-email-eblake@redhat.com> <87tx3qstww.fsf@blackfin.pond.sub.org> <54296DA9.2030801@redhat.com> Date: Mon, 29 Sep 2014 18:35:29 +0200 In-Reply-To: <54296DA9.2030801@redhat.com> (Eric Blake's message of "Mon, 29 Sep 2014 08:33:13 -0600") Message-ID: <8761g6fkq6.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v4 14/19] qapi: More rigorous checking for type safety bypass List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Luiz Capitulino , Fam Zheng , qemu-devel@nongnu.org, wenchaoqemu@gmail.com Eric Blake writes: > On 09/29/2014 02:38 AM, Markus Armbruster wrote: >> Eric Blake 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 Your choice. I certainly don't want the silly 'no' block your series. >>> @@ -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. Got it, thanks! [...]