ShellPkg: Replace the usage of StrnCpy with CopyMem to avoid potential buffer overflow and refine the code style.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Signed-off-by: Yao Jiewen <jiewen.yao@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16083 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin
2014-09-10 01:03:43 +00:00
committed by shenshushi
parent c9f4d4838c
commit 323d3d1118

View File

@ -1140,6 +1140,7 @@ CreateFileInterfaceEnv(
) )
{ {
EFI_FILE_PROTOCOL_ENVIRONMENT *EnvFileInterface; EFI_FILE_PROTOCOL_ENVIRONMENT *EnvFileInterface;
UINTN EnvNameSize;
if (EnvName == NULL) { if (EnvName == NULL) {
return (NULL); return (NULL);
@ -1148,7 +1149,8 @@ CreateFileInterfaceEnv(
// //
// Get some memory // Get some memory
// //
EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+StrSize(EnvName)); EnvNameSize = StrSize(EnvName);
EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+EnvNameSize);
if (EnvFileInterface == NULL){ if (EnvFileInterface == NULL){
return (NULL); return (NULL);
} }
@ -1167,7 +1169,7 @@ CreateFileInterfaceEnv(
EnvFileInterface->Delete = FileInterfaceEnvDelete; EnvFileInterface->Delete = FileInterfaceEnvDelete;
EnvFileInterface->Read = FileInterfaceEnvRead; EnvFileInterface->Read = FileInterfaceEnvRead;
StrnCpy(EnvFileInterface->Name, EnvName, StrLen(EnvName)); CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize);
// //
// Assign the different members for Volatile and Non-Volatile variables // Assign the different members for Volatile and Non-Volatile variables