check memory allocations for success.

check pointer before access.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11503 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey 2011-04-04 21:41:24 +00:00
parent 4aa4377fda
commit cbdd109b43
5 changed files with 48 additions and 33 deletions

View File

@ -2760,7 +2760,7 @@ FileBufferMovePosition (
//
FileBuffer.FilePosition.Column = NewFilePosCol;
if (ColGap < 0) {
Abs = -ColGap;
Abs = (UINTN)(-ColGap);
FileBuffer.DisplayPosition.Column -= Abs;
} else {
FileBuffer.DisplayPosition.Column += ColGap;

View File

@ -205,15 +205,20 @@ ShellCommandRunSetVar (
Data++;
Data++;
Buffer = AllocateZeroPool(StrSize(Data));
UnicodeSPrint(Buffer, StrSize(Data), L"%s", Data);
((CHAR16*)Buffer)[StrLen(Buffer)-1] = CHAR_NULL;
Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrSize(Buffer)-sizeof(CHAR16), Buffer);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);
ShellStatus = SHELL_ACCESS_DENIED;
if (Buffer == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
ASSERT(ShellStatus == SHELL_SUCCESS);
UnicodeSPrint(Buffer, StrSize(Data), L"%s", Data);
((CHAR16*)Buffer)[StrLen(Buffer)-1] = CHAR_NULL;
Status = gRT->SetVariable((CHAR16*)VariableName, &Guid, Attributes, StrSize(Buffer)-sizeof(CHAR16), Buffer);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_SET), gShellDebug1HiiHandle, &Guid, VariableName, Status);
ShellStatus = SHELL_ACCESS_DENIED;
} else {
ASSERT(ShellStatus == SHELL_SUCCESS);
}
}
} else if (StrnCmp(Data, L"--", 2) == 0) {
//

View File

@ -565,7 +565,9 @@ ShellCommandRunFor (
Info->RemoveSubstAlias = TRUE;
}
}
CurrentScriptFile->CurrentCommand->Data = Info;
if (CurrentScriptFile->CurrentCommand != NULL) {
CurrentScriptFile->CurrentCommand->Data = Info;
}
} else {
ShellPrintHiiEx(
-1,

View File

@ -113,14 +113,20 @@ HandleVol(
Size2 = StrSize(SysInfo->VolumeLabel);
if (Size1 > Size2) {
SysInfo = ReallocatePool((UINTN)SysInfo->Size, (UINTN)SysInfo->Size + Size1 - Size2, SysInfo);
if (SysInfo == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle);
ShellStatus = SHELL_OUT_OF_RESOURCES;
}
}
if (SysInfo != NULL) {
StrCpy ((CHAR16 *) SysInfo->VolumeLabel, Name);
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;
Status = EfiFpHandle->SetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo);
}
StrCpy ((CHAR16 *) SysInfo->VolumeLabel, Name);
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;
Status = EfiFpHandle->SetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo);
}
FreePool(SysInfo);
@ -154,22 +160,24 @@ HandleVol(
ASSERT(SysInfo != NULL);
//
// print VolumeInfo table
//
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_VOL_VOLINFO),
gShellLevel2HiiHandle,
SysInfo->VolumeLabel,
SysInfo->ReadOnly?L"r":L"rw",
SysInfo->VolumeSize,
SysInfo->FreeSpace,
SysInfo->BlockSize
);
SHELL_FREE_NON_NULL(SysInfo);
if (SysInfo != NULL) {
//
// print VolumeInfo table
//
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
NULL,
STRING_TOKEN (STR_VOL_VOLINFO),
gShellLevel2HiiHandle,
SysInfo->VolumeLabel,
SysInfo->ReadOnly?L"r":L"rw",
SysInfo->VolumeSize,
SysInfo->FreeSpace,
SysInfo->BlockSize
);
SHELL_FREE_NON_NULL(SysInfo);
}
return (ShellStatus);
}