ShellPkg/for: Fix potential null pointer deference

When "FOR %a %a IN A B C" is executed,
CurrentScriptFile->CurrentCommand->Data is NULL.
But the code assumes it's not NULL and tries to
deference it.

The patch fixes this issue.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
(cherry picked from commit 7162fdb037)
This commit is contained in:
Ruiyu Ni
2018-02-05 15:53:20 +08:00
parent 810bf8c328
commit c46ac8ca03

View File

@ -2,7 +2,7 @@
Main file for endfor and for shell level 1 functions. Main file for endfor and for shell level 1 functions.
(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR> (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR> Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -624,7 +624,9 @@ ShellCommandRunFor (
if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) { if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {
Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data; Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
if (CurrentScriptFile->CurrentCommand->Reset) { if (CurrentScriptFile->CurrentCommand->Reset) {
Info->CurrentValue = (CHAR16*)Info->Set; if (Info != NULL) {
Info->CurrentValue = (CHAR16*)Info->Set;
}
FirstPass = TRUE; FirstPass = TRUE;
CurrentScriptFile->CurrentCommand->Reset = FALSE; CurrentScriptFile->CurrentCommand->Reset = FALSE;
} }