From c5c994c573f3d4044fa5dde01a81ae5ed479d8fe Mon Sep 17 00:00:00 2001 From: Chen A Chen Date: Tue, 6 Dec 2016 13:56:46 +0800 Subject: ShellPkg/Application: Fix ">v" cannot update environment variable When ">v" is used to redirect the command output to environment variable (e.g.: "echo xxx >v yyy"), we only called SetVariable() to update the variable storage but forgot to update the cached environment variables in gShellEnvVarList. When updating the variable storage, the existing code unnecessary saved the ending NULL character into variable storage. The patch fixes all the above issues. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen A Chen Reviewed-by: Ruiyu Ni Reviewed-by: Jaben Carsey Reviewed-by: Tapan Shah --- ShellPkg/Application/Shell/ShellEnvVar.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ShellPkg/Application/Shell/ShellEnvVar.c') diff --git a/ShellPkg/Application/Shell/ShellEnvVar.c b/ShellPkg/Application/Shell/ShellEnvVar.c index 6d8c79b4ca..4c49c1ca98 100644 --- a/ShellPkg/Application/Shell/ShellEnvVar.c +++ b/ShellPkg/Application/Shell/ShellEnvVar.c @@ -178,7 +178,10 @@ GetEnvironmentVariableList( Status = EFI_OUT_OF_RESOURCES; } else { ValSize = ValBufferSize; - VarList->Val = AllocateZeroPool(ValSize); + // + // We need another CHAR16 to save '\0' in VarList->Val. + // + VarList->Val = AllocateZeroPool (ValSize + sizeof (CHAR16)); if (VarList->Val == NULL) { SHELL_FREE_NON_NULL(VarList); Status = EFI_OUT_OF_RESOURCES; @@ -188,7 +191,10 @@ GetEnvironmentVariableList( if (Status == EFI_BUFFER_TOO_SMALL){ ValBufferSize = ValSize > ValBufferSize * 2 ? ValSize : ValBufferSize * 2; SHELL_FREE_NON_NULL (VarList->Val); - VarList->Val = AllocateZeroPool(ValBufferSize); + // + // We need another CHAR16 to save '\0' in VarList->Val. + // + VarList->Val = AllocateZeroPool (ValBufferSize + sizeof (CHAR16)); if (VarList->Val == NULL) { SHELL_FREE_NON_NULL(VarList); Status = EFI_OUT_OF_RESOURCES; @@ -272,7 +278,7 @@ SetEnvironmentVariableList( ; !IsNull(ListHead, &Node->Link) ; Node = (ENV_VAR_LIST*)GetNextNode(ListHead, &Node->Link) ){ - Size = StrSize(Node->Val); + Size = StrSize (Node->Val) - sizeof (CHAR16); if (Node->Atts & EFI_VARIABLE_NON_VOLATILE) { Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(Node->Key, Size, Node->Val); } else { -- cgit v1.2.3