X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FSetVar.c;h=9e57998ff85f797be72b4caed6e7ee3bff24cc2d;hb=fba9b6ba24bbbed0666f4e184c95f6b15a581d49;hp=afccf7bd5821aa0a7740ae73225e5fb87387a1c5;hpb=33c031ee2092282a069ce07d30202082ceaf61fe;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c index afccf7bd58..9e57998ff8 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/SetVar.c @@ -1,7 +1,7 @@ /** @file Main file for SetVar shell Debug1 function. - Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2010 - 2013, 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 @@ -49,7 +49,6 @@ ShellCommandRunSetVar ( UINTN Size; UINTN LoopVar; EFI_DEVICE_PATH_PROTOCOL *DevPath; - EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *DevPathFromText; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; @@ -140,7 +139,8 @@ ShellCommandRunSetVar ( Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS; } if (ShellCommandLineGetFlag(Package, L"-rt")) { - Attributes |= EFI_VARIABLE_RUNTIME_ACCESS; + Attributes |= EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_BOOTSERVICE_ACCESS; } if (ShellCommandLineGetFlag(Package, L"-nv")) { Attributes |= EFI_VARIABLE_NON_VOLATILE; @@ -177,7 +177,9 @@ ShellCommandRunSetVar ( if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocateZeroPool(Size); Status = gRT->GetVariable((CHAR16*)VariableName, &Guid, &Attributes2, &Size, Buffer); - FreePool(Buffer); + if (Buffer != NULL) { + FreePool(Buffer); + } Attributes = Attributes2; } // @@ -205,15 +207,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) { // @@ -221,9 +228,7 @@ ShellCommandRunSetVar ( // Data++; Data++; - Status = gBS->LocateProtocol(&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID**)&DevPathFromText); - ASSERT_EFI_ERROR(Status); - DevPath = DevPathFromText->ConvertTextToDevicePath(Data); + DevPath = ConvertTextToDevicePath(Data); if (DevPath == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SETVAR_ERROR_DPFT), gShellDebug1HiiHandle, Status); ShellStatus = SHELL_INVALID_PARAMETER;