ShellPkg/ShellAddEnvVarToList: Handle memory allocation failure

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
Ruiyu Ni
2016-07-11 13:56:49 +08:00
parent 31e5b912b9
commit ffbc60a027
3 changed files with 43 additions and 33 deletions

View File

@ -2852,36 +2852,28 @@ InternalEfiShellSetEnv(
)
{
EFI_STATUS Status;
UINT32 Atts;
Atts = 0x0;
if (Value == NULL || StrLen(Value) == 0) {
Status = SHELL_DELETE_ENVIRONMENT_VARIABLE(Name);
if (!EFI_ERROR(Status)) {
ShellRemvoeEnvVarFromList(Name);
}
return Status;
} else {
SHELL_DELETE_ENVIRONMENT_VARIABLE(Name);
if (Volatile) {
Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(Name, StrSize(Value), Value);
if (!EFI_ERROR(Status)) {
Atts &= ~EFI_VARIABLE_NON_VOLATILE;
Atts |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
ShellAddEnvVarToList(Name, Value, StrSize(Value), Atts);
Status = ShellAddEnvVarToList(
Name, Value, StrSize(Value),
EFI_VARIABLE_BOOTSERVICE_ACCESS | (Volatile ? 0 : EFI_VARIABLE_NON_VOLATILE)
);
if (!EFI_ERROR (Status)) {
Status = Volatile
? SHELL_SET_ENVIRONMENT_VARIABLE_V(Name, StrSize(Value), Value)
: SHELL_SET_ENVIRONMENT_VARIABLE_NV(Name, StrSize(Value), Value);
if (EFI_ERROR (Status)) {
ShellRemvoeEnvVarFromList(Name);
}
return Status;
} else {
Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(Name, StrSize(Value), Value);
if (!EFI_ERROR(Status)) {
Atts |= EFI_VARIABLE_NON_VOLATILE;
Atts |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
ShellAddEnvVarToList(Name, Value, StrSize(Value), Atts);
}
return Status;
}
}
return Status;
}
/**