summaryrefslogtreecommitdiffstats
path: root/ShellPkg
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2023-04-26 19:39:27 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-06-02 08:34:00 +0000
commita8acc12dfd80e4b2770c5912b1dbe1a04ab649d6 (patch)
treeeca6378499cde3aae1ab1b226c65b0abed6eefd3 /ShellPkg
parent78262899d225eb30e5fbe6a88e85a4b1d8c04a61 (diff)
downloadedk2-a8acc12dfd80e4b2770c5912b1dbe1a04ab649d6.tar.gz
edk2-a8acc12dfd80e4b2770c5912b1dbe1a04ab649d6.tar.bz2
edk2-a8acc12dfd80e4b2770c5912b1dbe1a04ab649d6.zip
ShellPkgDisconnect: zero-initialize handles
In case ShellConvertStringToUint64() fails the Handles are left uninitialized. That can for example happen for Handle2 and Handle3 in case only one parameter was specified on the command line. Which can trigger the ASSERT() in line 185. Reproducer: boot ovmf to efi shell in qemu, using q35 machine type, then try disconnect the sata controller in efi shell. Fix that by explicitly setting them to NULL in that case. While being at it also simplify the logic and avoid pointlessly calling ShellConvertStringToUint64() in case ParamN is NULL. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Diffstat (limited to 'ShellPkg')
-rw-r--r--ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
index fd49d1f7ce..fac6463e3c 100644
--- a/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
+++ b/ShellPkg/Library/UefiShellDriver1CommandsLib/Disconnect.c
@@ -160,16 +160,23 @@ ShellCommandRunDisconnect (
Param1 = ShellCommandLineGetRawValue (Package, 1);
Param2 = ShellCommandLineGetRawValue (Package, 2);
Param3 = ShellCommandLineGetRawValue (Package, 3);
- if (!EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
- Handle1 = Param1 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate1) : NULL;
+
+ if (Param1 && !EFI_ERROR (ShellConvertStringToUint64 (Param1, &Intermediate1, TRUE, FALSE))) {
+ Handle1 = ConvertHandleIndexToHandle ((UINTN)Intermediate1);
+ } else {
+ Handle1 = NULL;
}
- if (!EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
- Handle2 = Param2 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate2) : NULL;
+ if (Param2 && !EFI_ERROR (ShellConvertStringToUint64 (Param2, &Intermediate2, TRUE, FALSE))) {
+ Handle2 = ConvertHandleIndexToHandle ((UINTN)Intermediate2);
+ } else {
+ Handle2 = NULL;
}
- if (!EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
- Handle3 = Param3 != NULL ? ConvertHandleIndexToHandle ((UINTN)Intermediate3) : NULL;
+ if (Param3 && !EFI_ERROR (ShellConvertStringToUint64 (Param3, &Intermediate3, TRUE, FALSE))) {
+ Handle3 = ConvertHandleIndexToHandle ((UINTN)Intermediate3);
+ } else {
+ Handle3 = NULL;
}
if ((Param1 != NULL) && (Handle1 == NULL)) {