From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a69NE-0004Ju-Gg for qemu-devel@nongnu.org; Mon, 07 Dec 2015 22:55:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a69ND-0003YT-Cu for qemu-devel@nongnu.org; Mon, 07 Dec 2015 22:55:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a69ND-0003Y9-6z for qemu-devel@nongnu.org; Mon, 07 Dec 2015 22:55:31 -0500 From: Eric Blake Date: Mon, 7 Dec 2015 20:55:02 -0700 Message-Id: <1449546921-6378-13-git-send-email-eblake@redhat.com> In-Reply-To: <1449546921-6378-1-git-send-email-eblake@redhat.com> References: <1449546921-6378-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH v7 12/31] qapi: Don't cast Enum* to int* List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, Michael Roth C compilers are allowed to represent enums as a smaller type than int, if all enum values fit in the smaller type. There are even compiler flags that force the use of this smaller representation, and using them changes the ABI of a binary. Therefore, our generated code for visit_type_ENUM() (for all qapi enums) was wrong for casting Enum* to int* when calling visit_type_enum(). It appears that no one has been doing this for qemu, because if they had, we are potentially dereferencing beyond bounds or even risking a SIGBUS on platforms where unaligned pointer dereferencing is fatal. Better is to avoid the practice entirely, and just use the correct types. This matches the fix for alternate qapi types, done earlier in "qapi: Simplify visiting of alternate types". Signed-off-by: Eric Blake --- v7: rebase on typo fix v6: new patch --- scripts/qapi-visit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py index 4a4f67d..6bd188b 100644 --- a/scripts/qapi-visit.py +++ b/scripts/qapi-visit.py @@ -178,12 +178,13 @@ out: def gen_visit_enum(name): - # FIXME cast from enum *obj to int * invalidly assumes enum is int return mcgen(''' void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error **errp) { - visit_type_enum(v, (int *)obj, %(c_name)s_lookup, "%(name)s", name, errp); + int tmp = *obj; + visit_type_enum(v, &tmp, %(c_name)s_lookup, "%(name)s", name, errp); + *obj = tmp; } ''', c_name=c_name(name), name=name) -- 2.4.3