From patchwork Mon Nov 14 17:29:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 125570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0D13BB71FE for ; Tue, 15 Nov 2011 04:29:36 +1100 (EST) Received: from localhost ([::1]:54614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQ0Lc-0002es-Ap for incoming@patchwork.ozlabs.org; Mon, 14 Nov 2011 12:29:32 -0500 Received: from eggs.gnu.org ([140.186.70.92]:55842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQ0LX-0002e4-Ae for qemu-devel@nongnu.org; Mon, 14 Nov 2011 12:29:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQ0LW-0008Gl-69 for qemu-devel@nongnu.org; Mon, 14 Nov 2011 12:29:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14567) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQ0LV-0008GL-UK for qemu-devel@nongnu.org; Mon, 14 Nov 2011 12:29:26 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAEHTMjv016283 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Nov 2011 12:29:22 -0500 Received: from doriath (ovpn-113-138.phx2.redhat.com [10.3.113.138]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAEHTKIj030119; Mon, 14 Nov 2011 12:29:21 -0500 Date: Mon, 14 Nov 2011 15:29:20 -0200 From: Luiz Capitulino To: qemu-devel Message-ID: <20111114152920.37edca6f@doriath> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1.0?] qapi: Check for negative enum values X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We don't currently check for negative enum values in qmp_output_type_enum(), this will very likely generate a segfault when triggered. However, it _seems_ that no code in tree can trigger this today. Signed-off-by: Luiz Capitulino Acked-by: Michael Roth --- I think it's a good idea to merge this one for 1.0, but I'd be ok to queue it for 1.1 in case we're only merging fixes for "real" bugs. I found this while extending the QAPI's unit-tests... qapi/qmp-output-visitor.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c index d67724e..f76d015 100644 --- a/qapi/qmp-output-visitor.c +++ b/qapi/qmp-output-visitor.c @@ -190,7 +190,7 @@ static void qmp_output_type_enum(Visitor *v, int *obj, const char *strings[], assert(strings); while (strings[i++] != NULL); - if (value >= i - 1) { + if (value < 0 || value >= i - 1) { error_set(errp, QERR_INVALID_PARAMETER, name ? name : "null"); return; }