ShellPkg: 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: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17730 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin
2015-06-30 03:18:31 +00:00
committed by shenshushi
parent cb9a7ebabc
commit e75390f029
18 changed files with 195 additions and 120 deletions

View File

@@ -1,7 +1,7 @@
/** @file
Utility functions used by the Dp application.
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -141,10 +141,10 @@ GetShortPdbFileName (
UINTN StartIndex;
UINTN EndIndex;
ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16));
ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16));
if (PdbFileName == NULL) {
StrnCpy (UnicodeBuffer, L" ", 1);
StrnCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ", 1);
} else {
StartIndex = 0;
for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)
@@ -261,7 +261,7 @@ GetNameFromHandle (
);
if (!EFI_ERROR (Status)) {
SHELL_FREE_NON_NULL (PlatformLanguage);
StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);
StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);
mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
return;
}
@@ -305,7 +305,7 @@ GetNameFromHandle (
//
// Method 3. Get the name string from FFS UI section
//
StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);
StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString);
mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
FreePool (NameString);
} else {
@@ -321,7 +321,7 @@ GetNameFromHandle (
//
NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);
if (NameString != NULL) {
StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);
StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString);
mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;
FreePool (NameString);
return;
@@ -334,7 +334,7 @@ GetNameFromHandle (
//
StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);
ASSERT (StringPtr != NULL);
StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);
StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);
FreePool (StringPtr);
}

View File

@@ -1,7 +1,7 @@
/** @file
Main file for support of shell consist mapping.
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -116,7 +116,7 @@ CatPrint (
ASSERT (Str->Str != NULL);
}
StrnCat (Str->Str, AppendStr, StringSize/sizeof(CHAR16) - 1 - StrLen(Str->Str));
StrCatS (Str->Str, StringSize/sizeof(CHAR16), AppendStr);
Str->Len = StringSize;
FreePool (AppendStr);

View File

@@ -2,7 +2,7 @@
Main file for DmpStore shell Debug1 function.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -406,7 +406,7 @@ CascadeProcessVariables (
FoundVarName = AllocateZeroPool (NameSize);
if (FoundVarName != NULL) {
if (PrevName != NULL) {
StrnCpy(FoundVarName, PrevName, NameSize/sizeof(CHAR16)-1);
StrCpyS(FoundVarName, NameSize/sizeof(CHAR16), PrevName);
}
Status = gRT->GetNextVariableName (&NameSize, FoundVarName, &FoundVarGuid);

View File

@@ -1,7 +1,7 @@
/** @file
Implements filebuffer interface functions.
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -507,7 +507,7 @@ FileBufferPrintLine (
PrintLine = AllocatePool (BufLen);
ASSERT (PrintLine != NULL);
StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));
StrnCpyS (PrintLine, BufLen/sizeof(CHAR16), Buffer, MIN(Limit, MainEditor.ScreenSize.Column));
for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
PrintLine[Limit] = L' ';
}

View File

@@ -3229,13 +3229,13 @@ QueryTable (
//
if ((High > Low && Key >= Low && Key <= High)
|| (Table[Index].Key == Key)) {
StrnCpy (Info, Table[Index].Info, InfoLen-1);
StrnCat (Info, L"\n", InfoLen - 1 - StrLen(Info));
StrCpyS (Info, InfoLen, Table[Index].Info);
StrCatS (Info, InfoLen, L"\n");
return Key;
}
}
StrnCpy (Info, L"Undefined Value\n", InfoLen - 1);
StrCpyS (Info, InfoLen, L"Undefined Value\n");
return QUERY_TABLE_UNFOUND;
}

View File

@@ -2,7 +2,7 @@
Main file for Drivers shell Driver1 function.
(C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -282,7 +282,7 @@ ShellCommandRunDrivers (
TruncatedDriverName = NULL;
if (!SfoFlag && (FullDriverName != NULL)) {
TruncatedDriverName = AllocateZeroPool ((MAX_LEN_DRIVER_NAME + 1) * sizeof (CHAR16));
StrnCpy (TruncatedDriverName, FullDriverName, MAX_LEN_DRIVER_NAME);
StrCpyS (TruncatedDriverName, MAX_LEN_DRIVER_NAME + 1, FullDriverName);
}
ShellPrintEx(

View File

@@ -2,7 +2,7 @@
Main file for cp shell level 2 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -427,20 +427,20 @@ ValidateAndCopyFiles(
// simple copy of a single file
//
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);
StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
} else {
StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
}
} else {
//
@@ -455,44 +455,44 @@ ValidateAndCopyFiles(
// Copy to the root of CWD
//
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool(CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
while (PathRemoveLastItem(DestPath));
StrnCat(DestPath, CleanFilePathStr+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
} else if (StrStr(CleanFilePathStr, L":") == NULL) {
if (Cwd != NULL) {
StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);
StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool(CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
} else {
StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);
StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;
}
StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
}
}

View File

@@ -2,7 +2,7 @@
Main file for mv shell level 2 function.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -187,7 +187,7 @@ GetDestinationLocation(
if (DestPath == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
StrCpyS(DestPath, StrSize(Cwd) / sizeof(CHAR16), Cwd);
while (PathRemoveLastItem(DestPath)) ;
//
@@ -220,13 +220,13 @@ GetDestinationLocation(
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
StrCpyS(DestPath, NewSize / sizeof(CHAR16), Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestParameter[0] != L'\\') {
StrCat(DestPath, L"\\");
StrCatS(DestPath, NewSize / sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestParameter[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCat(DestPath, DestParameter);
StrCatS(DestPath, NewSize / sizeof(CHAR16), DestParameter);
} else {
ASSERT(DestPath == NULL);
DestPath = StrnCatGrow(&DestPath, NULL, DestParameter, 0);
@@ -256,8 +256,8 @@ GetDestinationLocation(
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Node->FullName);
StrCat(DestPath, L"\\");
StrCpyS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), Node->FullName);
StrCatS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), L"\\");
} else {
//
// cant move multiple files onto a single file.
@@ -351,11 +351,11 @@ CreateFullDestPath(
return (EFI_OUT_OF_RESOURCES);
}
StrnCpy(*FullDestPath, *DestPath, Size / sizeof(CHAR16) - 1);
StrCpyS(*FullDestPath, Size / sizeof(CHAR16), *DestPath);
if ((*FullDestPath)[StrLen(*FullDestPath)-1] != L'\\' && FileName[0] != L'\\') {
StrnCat(*FullDestPath, L"\\",Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
StrCatS(*FullDestPath, Size / sizeof(CHAR16), L"\\");
}
StrnCat(*FullDestPath, FileName, Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
StrCatS(*FullDestPath, Size / sizeof(CHAR16), FileName);
return (EFI_SUCCESS);
}
@@ -403,10 +403,10 @@ MoveWithinFileSystems(
} else {
CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);
if (DestPath[0] != L'\\') {
StrCpy(NewFileInfo->FileName, L"\\");
StrCat(NewFileInfo->FileName, DestPath);
StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), L"\\");
StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);
} else {
StrCpy(NewFileInfo->FileName, DestPath);
StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);
}
Length = StrLen(NewFileInfo->FileName);
if (Length > 0) {
@@ -419,7 +419,7 @@ MoveWithinFileSystems(
//
NewFileInfo->FileName[Length] = CHAR_NULL;
}
StrCat(NewFileInfo->FileName, Node->FileName);
StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), Node->FileName);
}
NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);

View File

@@ -2,7 +2,7 @@
Main file for attrib shell level 2 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -132,9 +132,9 @@ CascadeDelete(
if (TempName == NULL) {
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
StrnCpy(TempName, Node->FullName, NewSize/sizeof(CHAR16) -1);
StrCpyS(TempName, NewSize/sizeof(CHAR16), Node->FullName);
TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL;
StrnCat(TempName, Node2->FullName, NewSize/sizeof(CHAR16) -1 - StrLen(TempName));
StrCatS(TempName, NewSize/sizeof(CHAR16), Node2->FullName);
FreePool((VOID*)Node2->FullName);
Node2->FullName = TempName;

View File

@@ -2,7 +2,7 @@
Main file for vol shell level 2 function.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -120,7 +120,10 @@ HandleVol(
}
}
if (SysInfo != NULL) {
StrnCpy ((CHAR16 *) SysInfo->VolumeLabel, Name, (Size1 > Size2?Size1/sizeof(CHAR16):Size2/sizeof(CHAR16))-1);
StrCpyS ( (CHAR16 *) SysInfo->VolumeLabel,
(Size1>Size2? Size1/sizeof(CHAR16) : Size2/sizeof(CHAR16)),
Name
);
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;
Status = EfiFpHandle->SetInfo(
EfiFpHandle,

View File

@@ -1713,8 +1713,8 @@ ShellFindFilePath (
if (TestPath == NULL) {
return (NULL);
}
StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1);
StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
StrCpyS(TestPath, Size/sizeof(CHAR16), Path);
StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
if (!EFI_ERROR(Status)){
if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
@@ -1746,12 +1746,12 @@ ShellFindFilePath (
*TempChar = CHAR_NULL;
}
if (TestPath[StrLen(TestPath)-1] != L'\\') {
StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");
}
if (FileName[0] == L'\\') {
FileName++;
}
StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
if (StrStr(Walker, L";") != NULL) {
Walker = StrStr(Walker, L";") + 1;
} else {
@@ -1820,9 +1820,9 @@ ShellFindFilePathEx (
return (NULL);
}
for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){
StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1);
StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);
if (ExtensionWalker != NULL) {
StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath));
StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);
}
TempChar = StrStr(TestPath, L";");
if (TempChar != NULL) {
@@ -2109,10 +2109,19 @@ InternalCommandLineParse (
CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
ASSERT(CurrentItemPackage->Value != NULL);
if (ValueSize == 0) {
StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1);
StrCpyS( CurrentItemPackage->Value,
CurrentValueSize/sizeof(CHAR16),
Argv[LoopCounter]
);
} else {
StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value));
StrCatS( CurrentItemPackage->Value,
CurrentValueSize/sizeof(CHAR16),
L" "
);
StrCatS( CurrentItemPackage->Value,
CurrentValueSize/sizeof(CHAR16),
Argv[LoopCounter]
);
}
ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
@@ -2635,14 +2644,14 @@ ShellCopySearchAndReplace(
FreePool(Replace);
return (EFI_BUFFER_TOO_SMALL);
}
StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString));
StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);
} else {
Size = StrSize(NewString);
if (Size + sizeof(CHAR16) > NewSize) {
FreePool(Replace);
return (EFI_BUFFER_TOO_SMALL);
}
StrnCat(NewString, SourceString, 1);
StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);
SourceString++;
}
}
@@ -3254,7 +3263,9 @@ StrnCatGrow (
if (*Destination == NULL) {
return (NULL);
}
return StrnCat(*Destination, Source, Count);
StrCatS(*Destination, Count + 1, Source);
return *Destination;
}
/**

View File

@@ -2,7 +2,7 @@
The implementation for ifcommand shell command.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -251,6 +251,8 @@ GetChildHandle (
Append OFFSET/WIDTH/VALUE items at the beginning of string.
@param[in, out] String The pointer to the string to append onto.
@param[in] MaxLen The max number of UNICODE char in String
including the terminate NULL char.
@param[in] Offset Offset value.
@param[in] Width Width value.
@param[in] Block Point to data buffer.
@@ -261,6 +263,7 @@ UINTN
EFIAPI
AppendOffsetWidthValue (
IN OUT CHAR16 *String,
IN UINTN MaxLen,
IN UINTN Offset,
IN UINTN Width,
IN CONST UINT8 *Block
@@ -271,16 +274,16 @@ AppendOffsetWidthValue (
OriString = String;
StrnCpy (String, L"&OFFSET=", 9);
StrnCpyS (String, MaxLen, L"&OFFSET=", 9);
String += StrLen (L"&OFFSET=");
String += UnicodeSPrint (String, 20, L"%x", Offset);
StrnCpy (String,L"&WIDTH=", 8);
StrnCpyS (String, MaxLen, L"&WIDTH=", 8);
String += StrLen (L"&WIDTH=");
String += UnicodeSPrint (String, 20, L"%x", Width);
if (Block != NULL) {
StrnCpy (String,L"&VALUE=", 8);
StrnCpyS (String, MaxLen, L"&VALUE=", 8);
String += StrLen (L"&VALUE=");
while ((Width--) != 0) {
String += UnicodeSPrint (String, 20, L"%x", Block[Width]);
@@ -342,6 +345,7 @@ ConstructConfigHdr (
{
EFI_STATUS Status;
CHAR16 *ConfigHdr;
UINTN ConfigHdrBufferSize;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
CHAR16 *String;
UINTN Index;
@@ -363,13 +367,14 @@ ConstructConfigHdr (
DevicePathLength = GetDevicePathSize (DevicePath);
NameLength = StrLen (Name);
ConfigHdr = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16));
ConfigHdrBufferSize = (5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16);
ConfigHdr = AllocateZeroPool (ConfigHdrBufferSize);
if (ConfigHdr == NULL) {
return NULL;
}
String = ConfigHdr;
StrnCpy (String, L"GUID=", 6);
StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"GUID=", 6);
String += StrLen (L"GUID=");
//
@@ -382,7 +387,7 @@ ConstructConfigHdr (
//
// Append L"&NAME="
//
StrnCpy (String, L"&NAME=", 7);
StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&NAME=", 7);
String += StrLen (L"&NAME=");
for (Index = 0; Index < NameLength ; Index++) {
String += UnicodeSPrint (String, 10, L"00%x", Name[Index]);
@@ -391,7 +396,7 @@ ConstructConfigHdr (
//
// Append L"&PATH="
//
StrnCpy (String, L"&PATH=", 7);
StrnCpyS (String, ConfigHdrBufferSize/sizeof(CHAR16), L"&PATH=", 7);
String += StrLen (L"&PATH=");
for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {
String += UnicodeSPrint (String, 6, L"%02x", *Buffer++);
@@ -548,6 +553,7 @@ IfconfigGetAllNicInfoByHii (
EFI_HANDLE *Handles;
UINTN HandleCount;
CHAR16 *ConfigResp;
UINTN ConfigRespBufferSize;
CHAR16 *ConfigHdr;
UINTN Index;
CHAR16 *AccessProgress;
@@ -612,13 +618,14 @@ IfconfigGetAllNicInfoByHii (
} else {
Length = 0;
}
ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));
ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
if (ConfigResp == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_ERROR;
}
if (ConfigHdr != NULL) {
StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
}
//
@@ -626,7 +633,12 @@ IfconfigGetAllNicInfoByHii (
//
String = ConfigResp + Length;
Offset = 0;
AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);
AppendOffsetWidthValue (String,
ConfigRespBufferSize/sizeof(CHAR16) - Length,
Offset,
NIC_ITEM_CONFIG_SIZE,
NULL
);
NicInfo = AllocateZeroPool (sizeof (NIC_INFO));
if (NicInfo == NULL) {
@@ -754,6 +766,7 @@ IfconfigSetNicAddrByHii (
SHELL_STATUS ShellStatus;
NIC_IP4_CONFIG_INFO *NicConfig;
CHAR16 *ConfigResp;
UINTN ConfigRespBufferSize;
CHAR16 *ConfigHdr;
CHAR16 *AccessProgress;
CHAR16 *AccessResults;
@@ -785,13 +798,14 @@ IfconfigSetNicAddrByHii (
ShellStatus = SHELL_OUT_OF_RESOURCES;
goto ON_EXIT;
}
ConfigResp = AllocateZeroPool ((Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16));
ConfigRespBufferSize = (Length + NIC_ITEM_CONFIG_SIZE * 2 + 100) * sizeof (CHAR16);
ConfigResp = AllocateZeroPool (ConfigRespBufferSize);
if (ConfigResp == NULL) {
ShellStatus = SHELL_OUT_OF_RESOURCES;
goto ON_EXIT;
}
if (ConfigHdr != NULL) {
StrnCpy (ConfigResp, ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
StrnCpyS (ConfigResp, ConfigRespBufferSize/sizeof(CHAR16), ConfigHdr, Length + NIC_ITEM_CONFIG_SIZE * 2 + 100 - 1);
}
NicConfig = AllocateZeroPool (NIC_ITEM_CONFIG_SIZE);
@@ -809,7 +823,12 @@ IfconfigSetNicAddrByHii (
//
String = ConfigResp + Length;
Offset = 0;
AppendOffsetWidthValue (String, Offset, NIC_ITEM_CONFIG_SIZE, NULL);
AppendOffsetWidthValue (String,
ConfigRespBufferSize/sizeof(CHAR16) - Length,
Offset,
NIC_ITEM_CONFIG_SIZE,
NULL
);
//
// Call HII helper function to generate configuration string