From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from huawei.com (huawei.com [45.249.212.191]) by mx.groups.io with SMTP id smtpd.web12.10586.1598958159569302676 for ; Tue, 01 Sep 2020 04:02:40 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.191, mailfrom: xiewenyi2@huawei.com) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id B6BFE5E9A0CA752443EE; Tue, 1 Sep 2020 19:02:36 +0800 (CST) Received: from HGH1000039998.huawei.com (10.184.68.188) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Tue, 1 Sep 2020 19:02:27 +0800 From: "wenyi,xie" To: , , , CC: , Subject: [PATCH EDK2 v1 1/1] EmulatorPkg/host: fix overflow in Mult Date: Tue, 1 Sep 2020 18:58:08 +0800 Message-ID: <1598957888-128729-2-git-send-email-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1598957888-128729-1-git-send-email-xiewenyi2@huawei.com> References: <1598957888-128729-1-git-send-email-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.184.68.188] X-CFilter-Loop: Reflected Content-Type: text/plain REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2947 When calculating memory regions and store the information in the gSystemMemory in file WinHost.c, the code below will cause overflow, because _wtoi (MemorySizeStr) return an int value and SIZE_1MB is also an int value, if MemorySizeStr is lager for example 2048, then result of multiplication will overflow. for (Index = 0, Done = FALSE; !Done; Index++) { // // Save the size of the memory and make a Unicode filename SystemMemory00 // gSystemMemory[Index].Size = _wtoi (MemorySizeStr) * SIZE_1MB; Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni Signed-off-by: Wenyi Xie --- EmulatorPkg/Win/Host/WinHost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EmulatorPkg/Win/Host/WinHost.c b/EmulatorPkg/Win/Host/WinHost.c index 0838c56ddea8..876cb8d4be8b 100644 --- a/EmulatorPkg/Win/Host/WinHost.c +++ b/EmulatorPkg/Win/Host/WinHost.c @@ -577,7 +577,7 @@ Returns: // // Save the size of the memory and make a Unicode filename SystemMemory00, ... // - gSystemMemory[Index].Size = _wtoi (MemorySizeStr) * SIZE_1MB; + gSystemMemory[Index].Size = ((UINT64)_wtoi (MemorySizeStr)) * ((UINT64)SIZE_1MB); // // Find the next region -- 2.20.1.windows.1