From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kZWqC-0007kR-VG for mharc-qemu-trivial@gnu.org; Mon, 02 Nov 2020 05:13:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWqB-0007hB-0Z; Mon, 02 Nov 2020 05:13:31 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWq9-00077m-2i; Mon, 02 Nov 2020 05:13:30 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CPpdy3gVHzhfYX; Mon, 2 Nov 2020 18:13:26 +0800 (CST) Received: from [10.174.187.138] (10.174.187.138) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Mon, 2 Nov 2020 18:13:17 +0800 Message-ID: <5F9FDBBD.4020607@huawei.com> Date: Mon, 2 Nov 2020 18:13:17 +0800 From: AlexChen User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= CC: Peter Maydell , QEMU Trivial , qemu-arm , QEMU , Subject: [PATCH V3] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference References: <5F9F8D88.9030102@huawei.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.187.138] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.32; envelope-from=alex.chen@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 05:10:42 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Nov 2020 10:13:31 -0000 In exynos4210_fimd_update(), the pointer 's' is dereferenced before checking it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking 's' is valid. Reported-by: Euler Robot Signed-off-by: Alex Chen Reviewed-by: Philippe Mathieu-Daudé --- hw/display/exynos4210_fimd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c index 4c16e1f5a0..34a960a976 100644 --- a/hw/display/exynos4210_fimd.c +++ b/hw/display/exynos4210_fimd.c @@ -1275,12 +1275,14 @@ static void exynos4210_fimd_update(void *opaque) bool blend = false; uint8_t *host_fb_addr; bool is_dirty = false; - const int global_width = (s->vidtcon[2] & FIMD_VIDTCON2_SIZE_MASK) + 1; + int global_width; if (!s || !s->console || !s->enabled || surface_bits_per_pixel(qemu_console_surface(s->console)) == 0) { return; } + + global_width = (s->vidtcon[2] & FIMD_VIDTCON2_SIZE_MASK) + 1; exynos4210_update_resolution(s); surface = qemu_console_surface(s->console); -- 2.19.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a19:6b17:0:0:0:0:0 with SMTP id d23csp3794590lfa; Mon, 2 Nov 2020 02:13:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwesUx6a7OaNZXk4d34vkp/4h5SeCSxiMMi+e9opjnu37xjL3la+QHBDINZLfCZJZjRthZQ X-Received: by 2002:a25:774f:: with SMTP id s76mr19221656ybc.235.1604312026454; Mon, 02 Nov 2020 02:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604312026; cv=none; d=google.com; s=arc-20160816; b=RwRR/0Wkb3ZnJcFff2NqW2zhJVj1fGNq3dRWveqP8DTv1ZjiAI18kVLzwJcDLGdzRA afHKGZuORWBYf/cDNkZclL73wcBiCjqdFaFY246N2AsvJkYPNN2cSueem1F02kWTwbkr 7KKbw2wMinliJ+1NhKJNsjINLavDk/O0EeJVo5KZar1Px6hhaKmlAW19D1lOxQa9x37H 6ETOOJGsXzWsy+dP+o9oQeCIy6NbAcD0FR4QGovZRlOtijhsKUolJ8nYdFBDrJpQb9Nv atnwcrw8wlYgv+ksnyUOcoP+PWWLmuNeIm596rm49rjrIfkDs6wGkXDuz0dx5uogepn0 3krA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:references:subject:to:mime-version:user-agent:from:date :message-id; bh=khdwCmGk1mnMdNyiYE4l4Iej34g3d35JDxN7nzx5gUk=; b=Y1BWoIhF7jSlsiroZnNxaP5QDGAYRa8ADjpTU7KBbuxNkCbBa9L7nXU2YF1FEKXXs4 92I5r+/JgHVne+RPVHBzHIy+4jryR/1gIBDqAzHb/ZFO+7aiXGGwu6q+/8dbAvoCeGLn mxsIx0YWsDTS3KjE74OpyVGGq+S7BRYPaIR0P+aEbaiULzsdLjLXGPFckJz2EgcDcuSg ZuBYNmcC9EDVrcDApOquFYKacjlPWNpnh8SwAuiQWQ6wIF1HOGnzSNR3LsTU0HS5V2A8 s+/XfOXaEgPhT1/kAXHokNNB/o3vBll3J/1l76qV67bmrbvGUxQSJ1f7GZJlxe4j4o5V BeLw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e3si14991936ybq.456.2020.11.02.02.13.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Nov 2020 02:13:46 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:47770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZWqP-0007k5-Q1 for alex.bennee@linaro.org; Mon, 02 Nov 2020 05:13:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWqB-0007hB-0Z; Mon, 02 Nov 2020 05:13:31 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZWq9-00077m-2i; Mon, 02 Nov 2020 05:13:30 -0500 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CPpdy3gVHzhfYX; Mon, 2 Nov 2020 18:13:26 +0800 (CST) Received: from [10.174.187.138] (10.174.187.138) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Mon, 2 Nov 2020 18:13:17 +0800 Message-ID: <5F9FDBBD.4020607@huawei.com> Date: Mon, 2 Nov 2020 18:13:17 +0800 From: AlexChen User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Subject: [PATCH V3] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference References: <5F9F8D88.9030102@huawei.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.187.138] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.32; envelope-from=alex.chen@huawei.com; helo=szxga06-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/02 05:10:42 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Trivial , Peter Maydell , qemu-arm , QEMU , zhang.zhanghailiang@huawei.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 57RVsdSXUosR In exynos4210_fimd_update(), the pointer 's' is dereferenced before checking it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking 's' is valid. Reported-by: Euler Robot Signed-off-by: Alex Chen Reviewed-by: Philippe Mathieu-Daudé --- hw/display/exynos4210_fimd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/display/exynos4210_fimd.c b/hw/display/exynos4210_fimd.c index 4c16e1f5a0..34a960a976 100644 --- a/hw/display/exynos4210_fimd.c +++ b/hw/display/exynos4210_fimd.c @@ -1275,12 +1275,14 @@ static void exynos4210_fimd_update(void *opaque) bool blend = false; uint8_t *host_fb_addr; bool is_dirty = false; - const int global_width = (s->vidtcon[2] & FIMD_VIDTCON2_SIZE_MASK) + 1; + int global_width; if (!s || !s->console || !s->enabled || surface_bits_per_pixel(qemu_console_surface(s->console)) == 0) { return; } + + global_width = (s->vidtcon[2] & FIMD_VIDTCON2_SIZE_MASK) + 1; exynos4210_update_resolution(s); surface = qemu_console_surface(s->console); -- 2.19.1