Skip to content

Commit

Permalink
fix: check length of minimega response slice before accessing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
activeshadow committed Sep 4, 2024
1 parent abf9349 commit 9024224
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/go/util/mm/minimega.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9024224

Please sign in to comment.