From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from huawei.com (huawei.com [45.249.212.190]) by mx.groups.io with SMTP id smtpd.web12.66.1600746174316410273 for ; Mon, 21 Sep 2020 20:42:55 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.190, mailfrom: xiewenyi2@huawei.com) Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 39294BE3BD08F358E8AE; Tue, 22 Sep 2020 11:42:51 +0800 (CST) Received: from [10.174.153.72] (10.174.153.72) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Tue, 22 Sep 2020 11:42:44 +0800 Subject: Re: [PATCH EDK2 v1 1/1] EmulatorPkg/host: fix overflow in Mult To: , , , CC: References: <1598957888-128729-1-git-send-email-xiewenyi2@huawei.com> <1598957888-128729-2-git-send-email-xiewenyi2@huawei.com> From: "wenyi,xie" Message-ID: Date: Tue, 22 Sep 2020 11:42:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.0.1 MIME-Version: 1.0 In-Reply-To: <1598957888-128729-2-git-send-email-xiewenyi2@huawei.com> X-Originating-IP: [10.174.153.72] X-CFilter-Loop: Reflected Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Hi all, Please review this patch when you're free, thanks. Regards Wenyi On 2020/9/1 18:58, Wenyi Xie wrote: > 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 >