Re: [edk2] [patch 1/2] IntelFrameworkModulePkg:Refine the code in LegacyBootMaintUiLib

2015-08-11 Thread Qiu, Shumin
Reviewed-by: Qiu Shumin shumin@intel.com

-Original Message-
From: Bi, Dandan 
Sent: Monday, August 10, 2015 5:32 PM
To: Dong, Eric; Qiu, Shumin; edk2-devel@lists.01.org
Subject: [patch 1/2] IntelFrameworkModulePkg:Refine the code in 
LegacyBootMaintUiLib

Refine the code in LegacyBootMaintUiLib to prevent the potential risk.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi dandan...@intel.com
---
 .../Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c| 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c 
b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
index 6a76842..4ebba33 100644
--- a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
+++ b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMai
+++ ntUi.c
@@ -142,10 +142,12 @@ OrderLegacyBootOption4SameType (
   *DisBootOption  = AllocatePool (BootOrderSize);
   *DisBootOptionCount = 0;
   *EnBootOptionCount  = 0;
   Index   = 0;
 
+  ASSERT (BbsIndexArray != NULL);
+  ASSERT (DeviceTypeArray != NULL);
   ASSERT (*EnBootOption != NULL);
   ASSERT (*DisBootOption != NULL);
 
   for (Index = 0; Index  BootOrderSize / sizeof (UINT16); Index++) {
   
@@ -173,10 +175,11 @@ OrderLegacyBootOption4SameType (
   // Record the corresponding Boot Option Numbers according to the DevOrder
   // Record the EnBootOption and DisBootOption according to the DevOrder
   //
   StartPosition = BootOrderSize / sizeof (UINT16);
   NewBootOption = AllocatePool (DevOrderCount * sizeof (UINT16));
+  ASSERT (NewBootOption != NULL);
   while (DevOrderCount-- != 0) {
 for (Index = 0; Index  BootOrderSize / sizeof (UINT16); Index++) {
   if (BbsIndexArray[Index] == (DevOrder[DevOrderCount]  0xFF)) {
 StartPosition = MIN (StartPosition, Index);
 NewBootOption[DevOrderCount] = BootOrder[Index]; @@ -1176,10 +1179,11 
@@ GetLegacyOptionsOrder (
   LEGACY_MENU_OPTION  *OptionMenu;
   UINT16  VarDevOrder;
   UINTN   Pos;
   UINTN   Bit;
   UINT8   *DisMap;
+  UINTN   TotalLength;
 
   LegacyDev = NULL;
   OptionMenu = NULL;
 
   DisMap = ZeroMem (mLegacyBootOptionPrivate-MaintainMapData-DisableMap, 
sizeof (mLegacyBootOptionPrivate-MaintainMapData-DisableMap));
@@ -1226,24 +1230,25 @@ GetLegacyOptionsOrder (
   }
 
   //
   // Create oneof tag here for FD/HD/CD #1 #2
   //
-  for (Index = 0; Index  OptionMenu-MenuNumber; Index++) {  
-VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + sizeof (BBS_TYPE) + 
sizeof (UINT16) + Index * sizeof (UINT16));
-  
+  for (Index = 0; Index  OptionMenu-MenuNumber; Index++) {
+TotalLength = sizeof (BBS_TYPE) + sizeof (UINT16) + Index * sizeof 
(UINT16);
+VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + TotalLength);
+
 if (0xFF00 == (VarDevOrder  0xFF00)) {
   LegacyDev[Index]  = 0xFF;
   Pos   = (VarDevOrder  0xFF) / 8;
   Bit   = 7 - ((VarDevOrder  0xFF) % 8);
   DisMap[Pos]   = (UINT8) (DisMap[Pos] | (UINT8) (1  Bit));
 } else {
   LegacyDev[Index] = VarDevOrder  0xFF;
 }
   }
 
-  VarData += sizeof (BBS_TYPE);
+  VarData ++;
   VarData += *(UINT16 *) VarData;
   DevOrder = (LEGACY_DEV_ORDER_ENTRY *) VarData;
 }
   }
 
--
1.9.5.msysgit.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [patch 1/2] IntelFrameworkModulePkg:Refine the code in LegacyBootMaintUiLib

2015-08-10 Thread Dandan Bi
Refine the code in LegacyBootMaintUiLib to prevent the potential risk.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi dandan...@intel.com
---
 .../Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c| 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c 
b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
index 6a76842..4ebba33 100644
--- a/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
+++ b/IntelFrameworkModulePkg/Library/LegacyBootMaintUiLib/LegacyBootMaintUi.c
@@ -142,10 +142,12 @@ OrderLegacyBootOption4SameType (
   *DisBootOption  = AllocatePool (BootOrderSize);
   *DisBootOptionCount = 0;
   *EnBootOptionCount  = 0;
   Index   = 0;
 
+  ASSERT (BbsIndexArray != NULL);
+  ASSERT (DeviceTypeArray != NULL);
   ASSERT (*EnBootOption != NULL);
   ASSERT (*DisBootOption != NULL);
 
   for (Index = 0; Index  BootOrderSize / sizeof (UINT16); Index++) {
   
@@ -173,10 +175,11 @@ OrderLegacyBootOption4SameType (
   // Record the corresponding Boot Option Numbers according to the DevOrder
   // Record the EnBootOption and DisBootOption according to the DevOrder
   //
   StartPosition = BootOrderSize / sizeof (UINT16);
   NewBootOption = AllocatePool (DevOrderCount * sizeof (UINT16));
+  ASSERT (NewBootOption != NULL);
   while (DevOrderCount-- != 0) {
 for (Index = 0; Index  BootOrderSize / sizeof (UINT16); Index++) {
   if (BbsIndexArray[Index] == (DevOrder[DevOrderCount]  0xFF)) {
 StartPosition = MIN (StartPosition, Index);
 NewBootOption[DevOrderCount] = BootOrder[Index];
@@ -1176,10 +1179,11 @@ GetLegacyOptionsOrder (
   LEGACY_MENU_OPTION  *OptionMenu;
   UINT16  VarDevOrder;
   UINTN   Pos;
   UINTN   Bit;
   UINT8   *DisMap;
+  UINTN   TotalLength;
 
   LegacyDev = NULL;
   OptionMenu = NULL;
 
   DisMap = ZeroMem (mLegacyBootOptionPrivate-MaintainMapData-DisableMap, 
sizeof (mLegacyBootOptionPrivate-MaintainMapData-DisableMap));
@@ -1226,24 +1230,25 @@ GetLegacyOptionsOrder (
   }
 
   //
   // Create oneof tag here for FD/HD/CD #1 #2
   //
-  for (Index = 0; Index  OptionMenu-MenuNumber; Index++) {  
-VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + sizeof (BBS_TYPE) + 
sizeof (UINT16) + Index * sizeof (UINT16));
-  
+  for (Index = 0; Index  OptionMenu-MenuNumber; Index++) {
+TotalLength = sizeof (BBS_TYPE) + sizeof (UINT16) + Index * sizeof 
(UINT16);
+VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + TotalLength);
+
 if (0xFF00 == (VarDevOrder  0xFF00)) {
   LegacyDev[Index]  = 0xFF;
   Pos   = (VarDevOrder  0xFF) / 8;
   Bit   = 7 - ((VarDevOrder  0xFF) % 8);
   DisMap[Pos]   = (UINT8) (DisMap[Pos] | (UINT8) (1  Bit));
 } else {
   LegacyDev[Index] = VarDevOrder  0xFF;
 }
   }
 
-  VarData += sizeof (BBS_TYPE);
+  VarData ++;
   VarData += *(UINT16 *) VarData;
   DevOrder = (LEGACY_DEV_ORDER_ENTRY *) VarData;
 }
   }
 
-- 
1.9.5.msysgit.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel