From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kZRdW-0004WS-Pe for mharc-qemu-trivial@gnu.org; Sun, 01 Nov 2020 23:40:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZRdU-0004Vt-BQ; Sun, 01 Nov 2020 23:40:04 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZRdR-0004ER-Uz; Sun, 01 Nov 2020 23:40:03 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CPgDt4XDjz6yM6; Mon, 2 Nov 2020 12:39:42 +0800 (CST) Received: from [10.174.187.138] (10.174.187.138) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Mon, 2 Nov 2020 12:39:37 +0800 Message-ID: <5F9F8D88.9030102@huawei.com> Date: Mon, 2 Nov 2020 12:39:36 +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: Peter Maydell CC: qemu-arm , QEMU , QEMU Trivial , Subject: [PATCH V2] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.187.138] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.35; envelope-from=alex.chen@huawei.com; helo=szxga07-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/01 23:39:44 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 04:40:04 -0000 In exynos4210_fimd_update(), the pointer s is dereferinced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking that the s is valid. Reported-by: Euler Robot Signed-off-by: Alex Chen --- 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 d23csp3615817lfa; Sun, 1 Nov 2020 20:40:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9f4mSRCExaYqek0fd9aSXYvMrygD9c1C5DYkPVv9moquVRkNUwEYEk2+TbfNPBLskZ85t X-Received: by 2002:a25:6dc6:: with SMTP id i189mr18408677ybc.299.1604292023431; Sun, 01 Nov 2020 20:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604292023; cv=none; d=google.com; s=arc-20160816; b=zV8UA+9a7Q0cBxs6ubCq+4lK0h88ttqCiC+YS/Ij85sESWAHjkcbG1p5DJYCYOm/tA W8RCw3mentJhGtSjfamV2O0BUdk99Z6UOZywHjeAAc2MUGzw6enLy8J5ayaC5g6dy1bO 0cAT2JbLop0KYfad++Go01IfaGXKlJe3ymwCCtbMgOIDH4jS5qcH+ti2KRVaV60cVYUb tWE65fm8Z6emP3NIbbLN8hAw0t0FdkGzsnyJLW7GYscDMnLLF1pGRQ5ozgcSVjvupDmC uCf5kNxTrlT5AH9vjln3Qf5208vIwDw9AK2Jt/YtQDB2lhwcvrnsBpbtWCnWgM1eBm6q ejHQ== 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 :subject:to:mime-version:user-agent:from:date:message-id; bh=ORfjUg/N/iwLjXM/hWlk+BKtRJcG7zxkH+tFmd9JSMc=; b=OQ+jFVfEY/kRQFDsNE3uzZRB7vyLA/a8dzocwsi4nSJBg28X1i1QFicjx3X/2WGXBR gd3m8ssNp8gp1ppvGbUANtzT+QjX71YG5xqJOl3DMfRUPO0YuRABIcbpriE1qIqk++B0 FaGAAWUI1laBxF8QocYz7BWYtW/GhKu+iSwBBwRFtaXDIppBgCK4TgzedOn5LHsTXTFs fsyt3X4ZbhHAurrhtDHLYvBbwO72UI7wCS9tTEvOQjf0KJtObvvfZ69ylXOkfNRsZ6a1 0YXqjrAix+JMm/3vsqbd6mxkSc19ChY8+GagthJeKRfiEoDVujPG9fyQ47aiBbkXFSMu RCbQ== 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 q2si14521297ybp.400.2020.11.01.20.40.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 01 Nov 2020 20:40:23 -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]:40492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kZRdm-0004WP-5o for alex.bennee@linaro.org; Sun, 01 Nov 2020 23:40:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZRdU-0004Vt-BQ; Sun, 01 Nov 2020 23:40:04 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kZRdR-0004ER-Uz; Sun, 01 Nov 2020 23:40:03 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CPgDt4XDjz6yM6; Mon, 2 Nov 2020 12:39:42 +0800 (CST) Received: from [10.174.187.138] (10.174.187.138) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Mon, 2 Nov 2020 12:39:37 +0800 Message-ID: <5F9F8D88.9030102@huawei.com> Date: Mon, 2 Nov 2020 12:39:36 +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: Peter Maydell Subject: [PATCH V2] hw/display/exynos4210_fimd: Fix potential NULL pointer dereference Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.187.138] X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.35; envelope-from=alex.chen@huawei.com; helo=szxga07-in.huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/01 23:39:44 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 , qemu-arm , QEMU , zhang.zhanghailiang@huawei.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: 1936UdSjFgLI In exynos4210_fimd_update(), the pointer s is dereferinced before being check if it is valid, which may lead to NULL pointer dereference. So move the assignment to global_width after checking that the s is valid. Reported-by: Euler Robot Signed-off-by: Alex Chen --- 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