]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
MdeModulePkg/Library/UefiBootManagerLib: Use safe string functions to refine code.
[mirror_edk2.git] / MdeModulePkg / Library / UefiBootManagerLib / BmBoot.c
index 2d3d57b3e9166bfc503445759393c970d7f09432..028edc35d53963f9c309b7bd0bdfd291f7d09888 100644 (file)
@@ -552,6 +552,7 @@ BmGetUsbDescription (
   CHAR16                       *SerialNumber;\r
   CHAR16                       *Description;\r
   EFI_USB_DEVICE_DESCRIPTOR    DevDesc;\r
+  UINTN                        DescMaxSize;\r
 \r
   Status = gBS->HandleProtocol (\r
                   Handle,\r
@@ -606,15 +607,16 @@ BmGetUsbDescription (
     return NULL;\r
   }\r
 \r
-  Description = AllocateZeroPool (StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber));\r
+  DescMaxSize = StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber);\r
+  Description = AllocateZeroPool (DescMaxSize);\r
   ASSERT (Description != NULL);\r
-  StrCat (Description, Manufacturer);\r
-  StrCat (Description, L" ");\r
+  StrCatS (Description, DescMaxSize/sizeof(CHAR16), Manufacturer);\r
+  StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");\r
 \r
-  StrCat (Description, Product);  \r
-  StrCat (Description, L" ");\r
+  StrCatS (Description, DescMaxSize/sizeof(CHAR16), Product);  \r
+  StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");\r
 \r
-  StrCat (Description, SerialNumber);\r
+  StrCatS (Description, DescMaxSize/sizeof(CHAR16), SerialNumber);\r
 \r
   if (Manufacturer != &NullChar) {\r
     FreePool (Manufacturer);\r
@@ -774,8 +776,14 @@ BmGetBootDescription (
       //\r
       Temp = AllocatePool (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)); \r
       ASSERT (Temp != NULL);\r
-      StrCpy (Temp, mBmUefiPrefix);\r
-      StrCat (Temp, DefaultDescription);\r
+      StrCpyS ( Temp, \r
+                (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix))/sizeof(CHAR16), \r
+                mBmUefiPrefix\r
+                );\r
+      StrCatS ( Temp, \r
+                (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix))/sizeof(CHAR16), \r
+                DefaultDescription\r
+                );\r
       FreePool (DefaultDescription);\r
       DefaultDescription = Temp;\r
       break;\r