From 9024224ee739118e624c2a91b8d100a71bf1c0d8 Mon Sep 17 00:00:00 2001 From: "Bryan T. Richardson" Date: Wed, 4 Sep 2024 08:18:35 -0600 Subject: [PATCH] fix: check length of minimega response slice before accessing There are times when the `disk info` command does not return a valid response and the response length was not checked before trying to access it. --- src/go/util/mm/minimega.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/go/util/mm/minimega.go b/src/go/util/mm/minimega.go index f83e1b0e..06c8af71 100644 --- a/src/go/util/mm/minimega.go +++ b/src/go/util/mm/minimega.go @@ -218,14 +218,19 @@ func (this Minimega) GetVMInfo(opts ...Option) VMs { cmd.Command = fmt.Sprintf("mesh send %s %s", row["host"], cmd.Command) } - // Only expect one row returned - // TODO (btr): check length to avoid a panic. - resp := mmcli.RunTabular(cmd)[0] + resp := mmcli.RunTabular(cmd) - if resp["backingfile"] == "" { - vm.Disk = resp["image"] + if len(resp) == 0 { + vm.Disk = disk } else { - vm.Disk = resp["backingfile"] + // Only expect one row returned + info := resp[0] + + if info["backingfile"] == "" { + vm.Disk = info["image"] + } else { + vm.Disk = info["backingfile"] + } } } else { // Attempting to get disk info when not using a snapshot will cause a