From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WALHy-0003kM-Q9 for qemu-devel@nongnu.org; Mon, 03 Feb 2014 10:18:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WALHs-0005h8-R3 for qemu-devel@nongnu.org; Mon, 03 Feb 2014 10:18:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WALHs-0005gy-Ik for qemu-devel@nongnu.org; Mon, 03 Feb 2014 10:18:16 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s13FICcO031210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 3 Feb 2014 10:18:14 -0500 From: Gerd Hoffmann Date: Mon, 3 Feb 2014 16:18:03 +0100 Message-Id: <1391440685-24201-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1391440685-24201-1-git-send-email-kraxel@redhat.com> References: <1391440685-24201-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 2/4] hw/display/qxl: fix signed to unsigned comparison List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alon Levy , Gerd Hoffmann From: Alon Levy Several small signedness / overflow corrections to qxl_create_guest_primary: 1. use 64 bit unsigned for size to avoid overflow possible from two 32 bit multiplicants. 2. correct sign for requested_height 3. add a more verbose error message when setting guest bug state (which causes a complete guess blackout until reset, so it helps if it is verbose). Signed-off-by: Alon Levy Signed-off-by: Gerd Hoffmann --- hw/display/qxl.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/display/qxl.c b/hw/display/qxl.c index 56b61c8..334c271 100644 --- a/hw/display/qxl.c +++ b/hw/display/qxl.c @@ -19,6 +19,7 @@ */ #include +#include #include "qemu-common.h" #include "qemu/timer.h" @@ -1361,14 +1362,16 @@ static void qxl_create_guest_primary(PCIQXLDevice *qxl, int loadvm, { QXLDevSurfaceCreate surface; QXLSurfaceCreate *sc = &qxl->guest_primary.surface; - int size; - int requested_height = le32_to_cpu(sc->height); + uint32_t requested_height = le32_to_cpu(sc->height); int requested_stride = le32_to_cpu(sc->stride); - size = abs(requested_stride) * requested_height; - if (size > qxl->vgamem_size) { - qxl_set_guest_bug(qxl, "%s: requested primary larger then framebuffer" - " size", __func__); + if (requested_stride == INT32_MIN || + abs(requested_stride) * (uint64_t)requested_height + > qxl->vgamem_size) { + qxl_set_guest_bug(qxl, "%s: requested primary larger than framebuffer" + " stride %d x height %" PRIu32 " > %" PRIu32, + __func__, requested_stride, requested_height, + qxl->vgamem_size); return; } -- 1.8.3.1