diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-04-04 21:41:24 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-04-04 21:41:24 +0000 |
commit | cbdd109b43c8386d74a7bb40d892e5c2485f71f9 (patch) | |
tree | 55cecf05db45228dae0f65785412b3eb7ce537a7 /ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c | |
parent | 4aa4377fdab7a01995b2f32e2a96c8340531cb6e (diff) | |
download | edk2-cbdd109b43c8386d74a7bb40d892e5c2485f71f9.tar.gz edk2-cbdd109b43c8386d74a7bb40d892e5c2485f71f9.tar.bz2 edk2-cbdd109b43c8386d74a7bb40d892e5c2485f71f9.zip |
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
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c')
-rw-r--r-- | ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index afccf7bd58..34eb6af8ac 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -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) {
//
|