Refine code to make it more safely.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15593 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
45295cf5a5
commit
81cd2f536e
@ -509,6 +509,7 @@ UefiMain (
|
|||||||
// Reset page break back to default.
|
// Reset page break back to default.
|
||||||
//
|
//
|
||||||
ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);
|
ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);
|
||||||
|
ASSERT (ShellInfoObject.ConsoleInfo != NULL);
|
||||||
ShellInfoObject.ConsoleInfo->Enabled = TRUE;
|
ShellInfoObject.ConsoleInfo->Enabled = TRUE;
|
||||||
ShellInfoObject.ConsoleInfo->RowCounter = 0;
|
ShellInfoObject.ConsoleInfo->RowCounter = 0;
|
||||||
|
|
||||||
@ -2091,6 +2092,7 @@ ProcessCommandLineToFinal(
|
|||||||
if (EFI_ERROR(Status)) {
|
if (EFI_ERROR(Status)) {
|
||||||
return (Status);
|
return (Status);
|
||||||
}
|
}
|
||||||
|
ASSERT (*CmdLine != NULL);
|
||||||
|
|
||||||
TrimSpaces(CmdLine);
|
TrimSpaces(CmdLine);
|
||||||
|
|
||||||
|
@ -460,6 +460,7 @@ EfiShellGetFilePathFromDevicePath(
|
|||||||
ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
|
ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));
|
||||||
|
|
||||||
AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);
|
AlignedNode = AllocateCopyPool (DevicePathNodeLength(FilePath), FilePath);
|
||||||
|
ASSERT (AlignedNode != NULL);
|
||||||
|
|
||||||
// File Path Device Path Nodes 'can optionally add a "\" separator to
|
// File Path Device Path Nodes 'can optionally add a "\" separator to
|
||||||
// the beginning and/or the end of the Path Name string.'
|
// the beginning and/or the end of the Path Name string.'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Main file for bcfg shell Debug1 function.
|
Main file for bcfg shell Debug1 function.
|
||||||
|
|
||||||
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -1027,12 +1027,14 @@ BcfgDisplayDumpDebug1(
|
|||||||
Buffer);
|
Buffer);
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
Buffer = AllocateZeroPool(BufferSize);
|
Buffer = AllocateZeroPool(BufferSize);
|
||||||
Status = gRT->GetVariable(
|
if (Buffer != NULL) {
|
||||||
VariableName,
|
Status = gRT->GetVariable(
|
||||||
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
VariableName,
|
||||||
NULL,
|
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
||||||
&BufferSize,
|
NULL,
|
||||||
Buffer);
|
&BufferSize,
|
||||||
|
Buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR(Status) || Buffer == NULL) {
|
if (EFI_ERROR(Status) || Buffer == NULL) {
|
||||||
@ -1042,8 +1044,12 @@ BcfgDisplayDumpDebug1(
|
|||||||
|
|
||||||
if ((*(UINT16*)(Buffer+4)) != 0) {
|
if ((*(UINT16*)(Buffer+4)) != 0) {
|
||||||
DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
|
DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
|
||||||
CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
|
if (DevPath != NULL) {
|
||||||
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
|
CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
|
||||||
|
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
|
||||||
|
} else {
|
||||||
|
DevPathString = NULL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DevPath = NULL;
|
DevPath = NULL;
|
||||||
DevPathString = NULL;
|
DevPathString = NULL;
|
||||||
@ -1213,12 +1219,16 @@ ShellCommandRunBcfg (
|
|||||||
CurrentOperation.Order);
|
CurrentOperation.Order);
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
|
CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
|
||||||
Status = gRT->GetVariable(
|
if (CurrentOperation.Order != NULL) {
|
||||||
CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
|
Status = gRT->GetVariable(
|
||||||
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
|
||||||
NULL,
|
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
||||||
&Length,
|
NULL,
|
||||||
CurrentOperation.Order);
|
&Length,
|
||||||
|
CurrentOperation.Order);
|
||||||
|
} else {
|
||||||
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Implements filebuffer interface functions.
|
Implements filebuffer interface functions.
|
||||||
|
|
||||||
Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved. <BR>
|
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved. <BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -489,8 +489,9 @@ FileBufferPrintLine (
|
|||||||
|
|
||||||
CHAR16 *Buffer;
|
CHAR16 *Buffer;
|
||||||
UINTN Limit;
|
UINTN Limit;
|
||||||
CHAR16 PrintLine[200];
|
CHAR16 *PrintLine;
|
||||||
CHAR16 PrintLine2[250];
|
CHAR16 *PrintLine2;
|
||||||
|
UINTN BufLen;
|
||||||
|
|
||||||
//
|
//
|
||||||
// print start from correct character
|
// print start from correct character
|
||||||
@ -502,13 +503,21 @@ FileBufferPrintLine (
|
|||||||
Limit = 0;
|
Limit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
StrnCpy (PrintLine, Buffer, MIN(MIN(Limit,MainEditor.ScreenSize.Column), 200));
|
BufLen = (MainEditor.ScreenSize.Column + 1) * sizeof (CHAR16);
|
||||||
|
PrintLine = AllocatePool (BufLen);
|
||||||
|
ASSERT (PrintLine != NULL);
|
||||||
|
|
||||||
|
StrnCpy (PrintLine, Buffer, MIN(Limit, MainEditor.ScreenSize.Column));
|
||||||
for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
|
for (; Limit < MainEditor.ScreenSize.Column; Limit++) {
|
||||||
PrintLine[Limit] = L' ';
|
PrintLine[Limit] = L' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;
|
PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;
|
||||||
ShellCopySearchAndReplace(PrintLine, PrintLine2, 250, L"%", L"^%", FALSE, FALSE);
|
|
||||||
|
PrintLine2 = AllocatePool (BufLen * 2);
|
||||||
|
ASSERT (PrintLine2 != NULL);
|
||||||
|
|
||||||
|
ShellCopySearchAndReplace(PrintLine, PrintLine2, BufLen * 2, L"%", L"^%", FALSE, FALSE);
|
||||||
|
|
||||||
ShellPrintEx (
|
ShellPrintEx (
|
||||||
0,
|
0,
|
||||||
@ -517,6 +526,9 @@ FileBufferPrintLine (
|
|||||||
PrintLine2
|
PrintLine2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
FreePool (PrintLine);
|
||||||
|
FreePool (PrintLine2);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Main file for Mm shell Debug1 function.
|
Main file for Mm shell Debug1 function.
|
||||||
|
|
||||||
Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2005 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -229,6 +229,7 @@ ShellCommandRunMm (
|
|||||||
SHELL_STATUS ShellStatus;
|
SHELL_STATUS ShellStatus;
|
||||||
CONST CHAR16 *Temp;
|
CONST CHAR16 *Temp;
|
||||||
|
|
||||||
|
Value = 0;
|
||||||
Address = 0;
|
Address = 0;
|
||||||
PciEAddress = 0;
|
PciEAddress = 0;
|
||||||
IoDev = NULL;
|
IoDev = NULL;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Main file for bcfg shell Install1 function.
|
Main file for bcfg shell Install1 function.
|
||||||
|
|
||||||
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -1040,8 +1040,12 @@ BcfgDisplayDumpInstall1(
|
|||||||
|
|
||||||
if ((*(UINT16*)(Buffer+4)) != 0) {
|
if ((*(UINT16*)(Buffer+4)) != 0) {
|
||||||
DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
|
DevPath = AllocateZeroPool(*(UINT16*)(Buffer+4));
|
||||||
CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
|
if (DevPath == NULL) {
|
||||||
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
|
DevPathString = NULL;
|
||||||
|
} else {
|
||||||
|
CopyMem(DevPath, Buffer+6+StrSize((CHAR16*)(Buffer+6)), *(UINT16*)(Buffer+4));
|
||||||
|
DevPathString = ConvertDevicePathToText(DevPath, TRUE, FALSE);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DevPath = NULL;
|
DevPath = NULL;
|
||||||
DevPathString = NULL;
|
DevPathString = NULL;
|
||||||
@ -1211,12 +1215,16 @@ ShellCommandRunBcfgInstall (
|
|||||||
CurrentOperation.Order);
|
CurrentOperation.Order);
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||||
CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
|
CurrentOperation.Order = AllocateZeroPool(Length+(4*sizeof(CurrentOperation.Order[0])));
|
||||||
Status = gRT->GetVariable(
|
if (CurrentOperation.Order == NULL) {
|
||||||
CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
|
ShellStatus = SHELL_OUT_OF_RESOURCES;
|
||||||
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
} else {
|
||||||
NULL,
|
Status = gRT->GetVariable(
|
||||||
&Length,
|
CurrentOperation.Target == BcfgTargetBootOrder?(CHAR16*)L"BootOrder":(CHAR16*)L"DriverOrder",
|
||||||
CurrentOperation.Order);
|
(EFI_GUID*)&gEfiGlobalVariableGuid,
|
||||||
|
NULL,
|
||||||
|
&Length,
|
||||||
|
CurrentOperation.Order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** @file
|
/** @file
|
||||||
Main file for endfor and for shell level 1 functions.
|
Main file for endfor and for shell level 1 functions.
|
||||||
|
|
||||||
Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
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
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
@ -333,7 +333,7 @@ ShellCommandRunFor (
|
|||||||
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
|
CurrentScriptFile = ShellCommandGetCurrentScriptFile();
|
||||||
ASSERT(CurrentScriptFile != NULL);
|
ASSERT(CurrentScriptFile != NULL);
|
||||||
|
|
||||||
if (CurrentScriptFile->CurrentCommand->Data == NULL) {
|
if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
|
||||||
FirstPass = TRUE;
|
FirstPass = TRUE;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -348,8 +348,7 @@ ShellCommandRunFor (
|
|||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
L"EndFor",
|
L"EndFor",
|
||||||
L"For",
|
L"For",
|
||||||
CurrentScriptFile->CurrentCommand!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
?CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
return (SHELL_DEVICE_ERROR);
|
return (SHELL_DEVICE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,9 +458,7 @@ ShellCommandRunFor (
|
|||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
ArgSet,
|
ArgSet,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
TempSpot = StrStr(ArgSetWalker, L")");
|
TempSpot = StrStr(ArgSetWalker, L")");
|
||||||
@ -483,9 +480,7 @@ ShellCommandRunFor (
|
|||||||
NULL,
|
NULL,
|
||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
*TempSpot = CHAR_NULL;
|
*TempSpot = CHAR_NULL;
|
||||||
@ -501,9 +496,7 @@ ShellCommandRunFor (
|
|||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
ArgSet,
|
ArgSet,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
if (ArgSetWalker[0] == L'-') {
|
if (ArgSetWalker[0] == L'-') {
|
||||||
@ -523,9 +516,7 @@ ShellCommandRunFor (
|
|||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
ArgSet,
|
ArgSet,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
if (ArgSetWalker[0] == L'-') {
|
if (ArgSetWalker[0] == L'-') {
|
||||||
@ -552,9 +543,7 @@ ShellCommandRunFor (
|
|||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
ArgSet,
|
ArgSet,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
} else {
|
} else {
|
||||||
if (*ArgSetWalker == L')') {
|
if (*ArgSetWalker == L')') {
|
||||||
@ -574,9 +563,7 @@ ShellCommandRunFor (
|
|||||||
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
|
||||||
gShellLevel1HiiHandle,
|
gShellLevel1HiiHandle,
|
||||||
ArgSet,
|
ArgSet,
|
||||||
CurrentScriptFile!=NULL
|
CurrentScriptFile->CurrentCommand->Line);
|
||||||
&& CurrentScriptFile->CurrentCommand!=NULL
|
|
||||||
? CurrentScriptFile->CurrentCommand->Line:0);
|
|
||||||
ShellStatus = SHELL_INVALID_PARAMETER;
|
ShellStatus = SHELL_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user