Skip to content

Commit

Permalink
Fix possible panic in libpod container restore
Browse files Browse the repository at this point in the history
We need to do a length check before we can access the
networkStatus slice by index to prevent a runtime panic.

Fixes containers#8026

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger committed Oct 15, 2020
1 parent 41eda41 commit 2e65497
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,13 +1024,15 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
if !options.IgnoreStaticMAC {
// Take the first device with a defined sandbox.
var MAC net.HardwareAddr
for _, n := range networkStatus[0].Interfaces {
if n.Sandbox != "" {
MAC, err = net.ParseMAC(n.Mac)
if err != nil {
return errors.Wrapf(err, "failed to parse MAC %v", n.Mac)
if len(networkStatus) > 0 {
for _, n := range networkStatus[0].Interfaces {
if n.Sandbox != "" {
MAC, err = net.ParseMAC(n.Mac)
if err != nil {
return errors.Wrapf(err, "failed to parse MAC %v", n.Mac)
}
break
}
break
}
}
if MAC != nil {
Expand Down

0 comments on commit 2e65497

Please sign in to comment.