Revision: 18214
          http://sourceforge.net/p/edk2/code/18214
Author:   dandanbi
Date:     2015-08-13 00:15:06 +0000 (Thu, 13 Aug 2015)
Log Message:
-----------
MdeModulePkg:Use safe string functions in UiApp.

Replace the unsafe string  functions with the safe one in UiApp.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <[email protected]>

Reviewed-by: Qiu Shumin <[email protected]>
Reviewed-by: Eric Dong <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/BootOption.c
    trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/FormGuid.h
    trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/UpdatePage.c
    trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/Variable.c
    trunk/edk2/MdeModulePkg/Application/UiApp/BootMngr/BootManager.c
    trunk/edk2/MdeModulePkg/Application/UiApp/DeviceMngr/DeviceManager.c
    trunk/edk2/MdeModulePkg/Application/UiApp/FrontPage.c

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/BootOption.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/BootOption.c    
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/BootOption.c    
2015-08-13 00:15:06 UTC (rev 18214)
@@ -786,7 +786,7 @@
 
     NewLoadContext->Description = AllocateZeroPool 
(StrSize((UINT16*)LoadOptionPtr));
     ASSERT (NewLoadContext->Description != NULL);
-    StrCpy (NewLoadContext->Description, (UINT16*)LoadOptionPtr);
+    StrCpyS (NewLoadContext->Description, StrSize((UINT16*)LoadOptionPtr) / 
sizeof (UINT16), (UINT16*)LoadOptionPtr);
     
     ASSERT (NewLoadContext->Description != NULL);
     NewMenuEntry->DisplayString = NewLoadContext->Description;
@@ -862,27 +862,25 @@
   IN  CHAR16  *Str2
   )
 {
-  UINTN   Size1;
-  UINTN   Size2;
+  UINTN   DestMax;
   CHAR16  *Str;
   CHAR16  *TmpStr;
   CHAR16  *Ptr;
   CHAR16  *LastSlash;
 
-  Size1 = StrSize (Str1);
-  Size2 = StrSize (Str2);
-  Str   = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16));
+  DestMax = (StrSize (Str1) + StrSize (Str2) + sizeof (CHAR16)) / sizeof 
(CHAR16);
+  Str   = AllocateZeroPool (DestMax * sizeof (CHAR16));
   ASSERT (Str != NULL);
 
-  TmpStr = AllocateZeroPool (Size1 + Size2 + sizeof (CHAR16)); 
+  TmpStr = AllocateZeroPool (DestMax * sizeof (CHAR16)); 
   ASSERT (TmpStr != NULL);
 
-  StrCat (Str, Str1);
+  StrCatS (Str, DestMax, Str1);
   if (!((*Str == '\\') && (*(Str + 1) == 0))) {
-    StrCat (Str, L"\\");
+    StrCatS (Str, DestMax, L"\\");
   }
 
-  StrCat (Str, Str2);
+  StrCatS (Str, DestMax, Str2);
 
   Ptr       = Str;
   LastSlash = Str;
@@ -895,11 +893,11 @@
       //
 
       //
-      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of 
two strings 
+      // Use TmpStr as a backup, as StrCpyS in BaseLib does not handle copy of 
two strings 
       // that overlap.
       //
-      StrCpy (TmpStr, Ptr + 3);
-      StrCpy (LastSlash, TmpStr);
+      StrCpyS (TmpStr, DestMax, Ptr + 3);
+      StrCpyS (LastSlash, DestMax - (UINTN) (LastSlash - Str), TmpStr);
       Ptr = LastSlash;
     } else if (*Ptr == '\\' && *(Ptr + 1) == '.' && *(Ptr + 2) == '\\') {
       //
@@ -907,11 +905,11 @@
       //
 
       //
-      // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of 
two strings 
+      // Use TmpStr as a backup, as StrCpyS in BaseLib does not handle copy of 
two strings 
       // that overlap.
       //
-      StrCpy (TmpStr, Ptr + 2);
-      StrCpy (Ptr, TmpStr);
+      StrCpyS (TmpStr, DestMax, Ptr + 2);
+      StrCpyS (Ptr, DestMax - (UINTN) (Ptr - Str), TmpStr);
       Ptr = LastSlash;
     } else if (*Ptr == '\\') {
       LastSlash = Ptr;

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/FormGuid.h
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/FormGuid.h      
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/FormGuid.h      
2015-08-13 00:15:06 UTC (rev 18214)
@@ -195,7 +195,7 @@
 /// This is the data structure used by File Explorer formset
 ///
 typedef struct {
-  UINT16  DescriptionData[75];
+  UINT16  DescriptionData[MAX_MENU_NUMBER];
   UINT16  OptionalData[127];
   UINT8   Active;
   UINT8   ForceReconnect;

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/UpdatePage.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/UpdatePage.c    
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/UpdatePage.c    
2015-08-13 00:15:06 UTC (rev 18214)
@@ -838,7 +838,7 @@
     //
     UnicodeValueToString (ModeString, 0, Col, 0);
     PStr = &ModeString[0];
-    StrnCat (PStr, L" x ", StrLen(L" x ") + 1);
+    StrnCatS (PStr, sizeof (ModeString) / sizeof (ModeString[0]), L" x ", 
StrLen(L" x ") + 1);
     PStr = PStr + StrLen (PStr);
     UnicodeValueToString (PStr , 0, Row, 0);
 

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/Variable.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/Variable.c      
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/BootMaint/Variable.c      
2015-08-13 00:15:06 UTC (rev 18214)
@@ -559,7 +559,7 @@
     );
 
   if (*DescriptionData == 0x0000) {
-    StrCpy (DescriptionData, DriverString);
+    StrCpyS (DescriptionData, MAX_MENU_NUMBER, DriverString);
   }
 
   BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (DescriptionData);
@@ -727,7 +727,7 @@
   UnicodeSPrint (BootString, sizeof (BootString), L"Boot%04x", Index);
 
   if (NvRamMap->DescriptionData[0] == 0x0000) {
-    StrCpy (NvRamMap->DescriptionData, BootString);
+    StrCpyS (NvRamMap->DescriptionData, sizeof (NvRamMap->DescriptionData) / 
sizeof (NvRamMap->DescriptionData[0]), BootString);
   }
 
   BufferSize = sizeof (UINT32) + sizeof (UINT16) + StrSize 
(NvRamMap->DescriptionData);

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/BootMngr/BootManager.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/BootMngr/BootManager.c    
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/BootMngr/BootManager.c    
2015-08-13 00:15:06 UTC (rev 18214)
@@ -236,6 +236,7 @@
   BOOLEAN                       IsLegacyOption;
   BOOLEAN                       NeedEndOp;
   UINT16                        KeyInput;
+  UINTN                         DestMax;
 
   DeviceType = (UINT16) -1;
 
@@ -325,10 +326,11 @@
 
     TempStr = UiDevicePathToStr (BootOption[Index].FilePath);
     TempSize = StrSize (TempStr);
+    DestMax = (TempSize + StrSize (L"Device Path : ")) / sizeof(CHAR16);
     HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));
     ASSERT (HelpString != NULL);
-    StrCat (HelpString, L"Device Path : ");
-    StrCat (HelpString, TempStr);
+    StrCatS (HelpString, DestMax, L"Device Path : ");
+    StrCatS (HelpString, DestMax, TempStr);
 
     HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);
 

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/DeviceMngr/DeviceManager.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/DeviceMngr/DeviceManager.c        
2015-08-12 12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/DeviceMngr/DeviceManager.c        
2015-08-13 00:15:06 UTC (rev 18214)
@@ -172,7 +172,7 @@
   }
 
   *PBuffer = String;
-  StrCpy(String, L"MAC:");
+  StrCpyS(String, BufferLen / sizeof (CHAR16), L"MAC:");
   String += 4;
   
   //

Modified: trunk/edk2/MdeModulePkg/Application/UiApp/FrontPage.c
===================================================================
--- trunk/edk2/MdeModulePkg/Application/UiApp/FrontPage.c       2015-08-12 
12:44:31 UTC (rev 18213)
+++ trunk/edk2/MdeModulePkg/Application/UiApp/FrontPage.c       2015-08-13 
00:15:06 UTC (rev 18214)
@@ -645,6 +645,7 @@
 {
   CHAR16  *StringBuffer;
   UINTN   Index;
+  UINTN   DestMax;
   UINT32  FreqMhz;
 
   if (Base10Exponent >= 6) {
@@ -655,13 +656,13 @@
   } else {
     FreqMhz = 0;
   }
-
+  DestMax = 0x20 / sizeof (CHAR16);
   StringBuffer = AllocateZeroPool (0x20);
   ASSERT (StringBuffer != NULL);
   Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);
-  StrCat (StringBuffer, L".");
+  StrCatS (StringBuffer, DestMax, L".");
   UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 
1000) / 10, 2);
-  StrCat (StringBuffer, L" GHz");
+  StrCatS (StringBuffer, DestMax, L" GHz");
   *String = (CHAR16 *) StringBuffer;
   return ;
 }
@@ -685,7 +686,7 @@
   StringBuffer = AllocateZeroPool (0x24);
   ASSERT (StringBuffer != NULL);
   UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 10);
-  StrCat (StringBuffer, L" MB RAM");
+  StrCatS (StringBuffer, 0x24 / sizeof (CHAR16), L" MB RAM");
 
   *String = (CHAR16 *) StringBuffer;
 
@@ -1542,8 +1543,8 @@
       ASSERT (StringBuffer1 != NULL);
       StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
       ASSERT (StringBuffer2 != NULL);
-      StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now.");
-      StrCpy (StringBuffer2, L"Press ENTER to reset");
+      StrCpyS (StringBuffer1, MAX_STRING_LEN, L"Configuration changed. Reset 
to apply it Now.");
+      StrCpyS (StringBuffer2, MAX_STRING_LEN, L"Press ENTER to reset");
       //
       // Popup a menu to notice user
       //


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to