diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-10 20:32:17 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-10 20:32:17 +0000 |
commit | ecae51177e83db0d99f8b4888ae4b866c18651b6 (patch) | |
tree | 61522e5d6294adbafeb58f35e61b090358c5126d /ShellPkg/Library/UefiShellDebug1CommandsLib | |
parent | beab0fc5e2ea7c676968991b1ae8e1fc72aef19f (diff) | |
download | edk2-platforms-ecae51177e83db0d99f8b4888ae4b866c18651b6.tar.xz |
ShellPkg: Add checks for NULL pointers.
This adds lots of pointer verification with ASSERTs only used when the condition should be impossible and never for memory allocation.
signed-off-by: jcarsey
reviewed-by: geekboy15a
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12523 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib')
6 files changed, 41 insertions, 16 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c index b59ef31682..01ef1997b2 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c @@ -49,6 +49,7 @@ ShellCommandRunComp ( UINTN DataSizeFromFile2;
CHAR16 *FileName1;
CHAR16 *FileName2;
+ CONST CHAR16 *TempParam;
ErrorCount = 0;
ShellStatus = SHELL_SUCCESS;
@@ -88,25 +89,29 @@ ShellCommandRunComp ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- FileName1 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
+ TempParam = ShellCommandLineGetRawValue(Package, 1);
+ ASSERT(TempParam != NULL);
+ FileName1 = ShellFindFilePath(TempParam);
if (FileName1 == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, TempParam, Status);
ShellStatus = SHELL_NOT_FOUND;
}
}
- FileName2 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 2));
+ TempParam = ShellCommandLineGetRawValue(Package, 2);
+ ASSERT(TempParam != NULL);
+ FileName2 = ShellFindFilePath(TempParam);
if (FileName2 == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2));
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, TempParam, Status);
ShellStatus = SHELL_NOT_FOUND;
}
}
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c index 06a3210ea0..b1f8327f4a 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Compress.c @@ -607,8 +607,10 @@ FreadCrc ( Advance the current position (read in new data if needed).
Delete outdated string info. Find a match string for current position.
+ @retval TRUE The operation was successful.
+ @retval FALSE The operation failed due to insufficient memory.
**/
-VOID
+BOOLEAN
EFIAPI
GetNextMatch (
VOID
@@ -621,6 +623,9 @@ GetNextMatch ( mPos++;
if (mPos == WNDSIZ * 2) {
Temp = AllocateZeroPool (WNDSIZ + MAXMATCH);
+ if (Temp == NULL) {
+ return (FALSE);
+ }
CopyMem (Temp, &mText[WNDSIZ], WNDSIZ + MAXMATCH);
CopyMem (&mText[0], Temp, WNDSIZ + MAXMATCH);
FreePool (Temp);
@@ -631,6 +636,8 @@ GetNextMatch ( DeleteNode ();
InsertNode ();
+
+ return (TRUE);
}
/**
@@ -1286,7 +1293,9 @@ Encode ( while (mRemainder > 0) {
LastMatchLen = mMatchLen;
LastMatchPos = mMatchPos;
- GetNextMatch ();
+ if (!GetNextMatch ()) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
if (mMatchLen > mRemainder) {
mMatchLen = mRemainder;
}
@@ -1306,7 +1315,9 @@ Encode ( (mPos - LastMatchPos - 2) & (WNDSIZ - 1));
LastMatchLen--;
while (LastMatchLen > 0) {
- GetNextMatch ();
+ if (!GetNextMatch ()) {
+ Status = EFI_OUT_OF_RESOURCES;
+ }
LastMatchLen--;
}
@@ -1318,7 +1329,7 @@ Encode ( HufEncodeEnd ();
FreeMemory ();
- return EFI_SUCCESS;
+ return (Status);
}
/**
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c index c4dbf80c96..c28f9bc591 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c @@ -36,6 +36,7 @@ ShellCommandRunEdit ( CONST CHAR16 *Cwd;
CHAR16 *Nfs;
CHAR16 *Spot;
+ CONST CHAR16 *TempParam;
// SHELL_FILE_HANDLE TempHandle;
Buffer = NULL;
@@ -101,7 +102,9 @@ ShellCommandRunEdit ( // if editor launched with file named
//
if (ShellCommandLineGetCount(Package) == 2) {
- FileBufferSetFileName (ShellCommandLineGetRawValue(Package, 1));
+ TempParam = ShellCommandLineGetRawValue(Package, 1);
+ ASSERT(TempParam != NULL);
+ FileBufferSetFileName (TempParam);
// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
// if (!EFI_ERROR(Status)) {
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index d4bb6217b0..25e8718980 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -42,6 +42,7 @@ ShellCommandRunEfiCompress ( VOID *InBuffer;
CHAR16 *InFileName;
CONST CHAR16 *OutFileName;
+ CONST CHAR16 *TempParam;
InFileName = NULL;
OutFileName = NULL;
@@ -82,10 +83,12 @@ ShellCommandRunEfiCompress ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- InFileName = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
+ TempParam = ShellCommandLineGetRawValue(Package, 1);
+ ASSERT(TempParam != NULL);
+ InFileName = ShellFindFilePath(TempParam);
OutFileName = ShellCommandLineGetRawValue(Package, 2);
if (InFileName == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
if (ShellIsDirectory(InFileName) == EFI_SUCCESS){
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c index 4b4671b455..35a32f1f3b 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c @@ -46,6 +46,7 @@ ShellCommandRunEfiDecompress ( UINT32 ScratchSize;
VOID *ScratchBuffer;
EFI_DECOMPRESS_PROTOCOL *Decompress;
+ CONST CHAR16 *TempParam;
InFileName = NULL;
OutFileName = NULL;
@@ -87,10 +88,12 @@ ShellCommandRunEfiDecompress ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- InFileName = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));
+ TempParam = ShellCommandLineGetRawValue(Package, 1);
+ ASSERT(TempParam != NULL);
+ InFileName = ShellFindFilePath(TempParam);
OutFileName = ShellCommandLineGetRawValue(Package, 2);
if (InFileName == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
if (ShellIsDirectory(InFileName) == EFI_SUCCESS){
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c index 8562662638..f5fb7d262a 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c @@ -169,7 +169,7 @@ HFileImageRead ( // you should set the status string
//
Status = ReadFileIntoBuffer (FileName, (VOID**)&Buffer, &HFileImage.Size, &HFileImage.ReadOnly);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR(Status) || Buffer == NULL) {
UnicodeBuffer = CatSPrint(NULL, L"Read error on file &s: %r", FileName, Status);
if (UnicodeBuffer == NULL) {
SHELL_FREE_NON_NULL(Buffer);
|