diff options
author | Chen A Chen <chen.a.chen@intel.com> | 2016-12-06 13:56:46 +0800 |
---|---|---|
committer | Ruiyu Ni <ruiyu.ni@intel.com> | 2016-12-09 09:26:28 +0800 |
commit | c5c994c573f3d4044fa5dde01a81ae5ed479d8fe (patch) | |
tree | 91a2a34a8466aa2edc2eb92491818260ce882f9a /ShellPkg/Application/Shell/ShellEnvVar.c | |
parent | 8537bd7ef64f2ccf3b0db515f30813d5c3311a5c (diff) | |
download | edk2-platforms-c5c994c573f3d4044fa5dde01a81ae5ed479d8fe.tar.xz |
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 <chen.a.chen@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hpe.com>
Diffstat (limited to 'ShellPkg/Application/Shell/ShellEnvVar.c')
-rw-r--r-- | ShellPkg/Application/Shell/ShellEnvVar.c | 12 |
1 files changed, 9 insertions, 3 deletions
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 {
|