MdeModulePkg/Library/UefiBootManagerLib: Use safe string functions to refine code.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17782 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin
2015-07-01 08:21:16 +00:00
committed by shenshushi
parent 93fd37dc0b
commit b6344b37c9
2 changed files with 28 additions and 16 deletions

View File

@ -552,6 +552,7 @@ BmGetUsbDescription (
CHAR16 *SerialNumber;
CHAR16 *Description;
EFI_USB_DEVICE_DESCRIPTOR DevDesc;
UINTN DescMaxSize;
Status = gBS->HandleProtocol (
Handle,
@ -606,15 +607,16 @@ BmGetUsbDescription (
return NULL;
}
Description = AllocateZeroPool (StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber));
DescMaxSize = StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber);
Description = AllocateZeroPool (DescMaxSize);
ASSERT (Description != NULL);
StrCat (Description, Manufacturer);
StrCat (Description, L" ");
StrCatS (Description, DescMaxSize/sizeof(CHAR16), Manufacturer);
StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");
StrCat (Description, Product);
StrCat (Description, L" ");
StrCatS (Description, DescMaxSize/sizeof(CHAR16), Product);
StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");
StrCat (Description, SerialNumber);
StrCatS (Description, DescMaxSize/sizeof(CHAR16), SerialNumber);
if (Manufacturer != &NullChar) {
FreePool (Manufacturer);
@ -774,8 +776,14 @@ BmGetBootDescription (
//
Temp = AllocatePool (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix));
ASSERT (Temp != NULL);
StrCpy (Temp, mBmUefiPrefix);
StrCat (Temp, DefaultDescription);
StrCpyS ( Temp,
(StrSize (DefaultDescription) + sizeof (mBmUefiPrefix))/sizeof(CHAR16),
mBmUefiPrefix
);
StrCatS ( Temp,
(StrSize (DefaultDescription) + sizeof (mBmUefiPrefix))/sizeof(CHAR16),
DefaultDescription
);
FreePool (DefaultDescription);
DefaultDescription = Temp;
break;