From patchwork Mon Dec 11 10:55:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prasad Pandit X-Patchwork-Id: 846901 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ywKdf4Qp0z9s7F for ; Mon, 11 Dec 2017 21:56:37 +1100 (AEDT) Received: from localhost ([::1]:52235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOLlC-0005dN-PL for incoming@patchwork.ozlabs.org; Mon, 11 Dec 2017 05:56:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eOLkk-0005bt-OU for qemu-devel@nongnu.org; Mon, 11 Dec 2017 05:56:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eOLkj-0001zW-Um for qemu-devel@nongnu.org; Mon, 11 Dec 2017 05:56:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eOLkf-0001uy-Iz; Mon, 11 Dec 2017 05:56:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 488AD6A7C1; Mon, 11 Dec 2017 10:55:59 +0000 (UTC) Received: from localhost.localdomain (vpn2-54-44.bne.redhat.com [10.64.54.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C1BA717515; Mon, 11 Dec 2017 10:55:54 +0000 (UTC) From: P J P To: Qemu Developers Date: Mon, 11 Dec 2017 16:25:46 +0530 Message-Id: <20171211105546.16466-1-ppandit@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 11 Dec 2017 10:55:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] display: check irq handler index before access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-arm@nongnu.org, Moguofang , Prasad J Pandit Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Prasad J Pandit The ctz32() routine could return value greater than TC6393XB_GPIOS=16. This could lead to an OOB array access. Add check to avoid it. Reported-by: Moguofang Signed-off-by: Prasad J Pandit --- hw/display/tc6393xb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/display/tc6393xb.c b/hw/display/tc6393xb.c index 74d10af3d4..78292cb847 100644 --- a/hw/display/tc6393xb.c +++ b/hw/display/tc6393xb.c @@ -175,6 +175,10 @@ static void tc6393xb_gpio_handler_update(TC6393xbState *s) for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) { bit = ctz32(diff); + if (bit >= TC6393XB_GPIOS) { + fprintf(stderr, "TC6393xb: no GPIO pin %d\n", bit); + return; + } qemu_set_irq(s->handler[bit], (level >> bit) & 1); }