public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bi, Dandan" <dandan.bi@intel.com>
To: "Wang, Jian J" <jian.j.wang@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH v3 3/3] IntelFrameworkModulePkg: Fix misuses of AllocateCopyPool
Date: Wed, 8 Nov 2017 02:33:44 +0000	[thread overview]
Message-ID: <3C0D5C461C9E904E8F62152F6274C0BB3B9D0474@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20171108021201.17436-4-jian.j.wang@intel.com>

Reviewed-by: Dandan Bi <dandan.bi@intel.com>

Thanks,
Dandan

-----Original Message-----
From: Wang, Jian J 
Sent: Wednesday, November 8, 2017 10:12 AM
To: edk2-devel@lists.01.org
Cc: Gao, Liming <liming.gao@intel.com>; Bi, Dandan <dandan.bi@intel.com>
Subject: [PATCH v3 3/3] IntelFrameworkModulePkg: Fix misuses of AllocateCopyPool

> v3:
>    No updates.

> v2:
> a. Use ReallocatePool instead of allocating then copying wherever 
> applicable

AllocateCopyPool(AllocationSize, *Buffer) will copy "AllocationSize" bytes of memory from old "Buffer" to new allocated one. If "AllocationSize" is bigger than size of "Buffer", heap memory overflow occurs during copy.

One solution is to allocate pool first then copy the necessary bytes to new memory. Another is using ReallocatePool instead if old buffer will be freed on spot.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bi Dandan <dandan.bi@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
---
 .../Universal/BdsDxe/DeviceMngr/DeviceManager.c                | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
index 125c49db5e..5103c7e5d1 100644
--- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c
+++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.
+++ c
@@ -480,7 +480,11 @@ AddIdToMacDeviceList (
   } else {
     mMacDeviceList.MaxListLen += MAX_MAC_ADDRESS_NODE_LIST_LEN;
     if (mMacDeviceList.CurListLen != 0) {
-      TempDeviceList = (MENU_INFO_ITEM *)AllocateCopyPool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen, (VOID *)mMacDeviceList.NodeList);
+      TempDeviceList = ReallocatePool (
+                         sizeof (MENU_INFO_ITEM) * mMacDeviceList.CurListLen,
+                         sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen,
+                         mMacDeviceList.NodeList
+                         );
     } else {
       TempDeviceList = (MENU_INFO_ITEM *)AllocatePool (sizeof (MENU_INFO_ITEM) * mMacDeviceList.MaxListLen);
     }
@@ -491,10 +495,6 @@ AddIdToMacDeviceList (
     TempDeviceList[mMacDeviceList.CurListLen].PromptId = PromptId;  
     TempDeviceList[mMacDeviceList.CurListLen].QuestionId = (EFI_QUESTION_ID) (mMacDeviceList.CurListLen + NETWORK_DEVICE_LIST_KEY_OFFSET);
     
-    if (mMacDeviceList.CurListLen > 0) {
-      FreePool(mMacDeviceList.NodeList);
-    }
-    
     mMacDeviceList.NodeList = TempDeviceList;
   }
   mMacDeviceList.CurListLen ++;
--
2.14.1.windows.1



      reply	other threads:[~2017-11-08  2:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08  2:11 [PATCH v3 0/3] Fix misuses of AllocateCopyPool Jian J Wang
2017-11-08  2:11 ` [PATCH v3 1/3] MdeModulePkg: " Jian J Wang
2017-11-08  2:37   ` Zeng, Star
2017-11-08  2:46     ` Wang, Jian J
2017-11-08  2:57       ` Zeng, Star
2017-11-08  2:12 ` [PATCH v3 2/3] ShellPkg: " Jian J Wang
2017-11-08 15:50   ` Carsey, Jaben
2017-11-09  1:03     ` Wang, Jian J
2017-11-08  2:12 ` [PATCH v3 3/3] IntelFrameworkModulePkg: " Jian J Wang
2017-11-08  2:33   ` Bi, Dandan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3C0D5C461C9E904E8F62152F6274C0BB3B9D0474@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox