From 2e65497deaf63cbb7a9521b49ac69bbe223970e4 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 15 Oct 2020 11:38:48 +0200 Subject: Fix possible panic in libpod container restore We need to do a length check before we can access the networkStatus slice by index to prevent a runtime panic. Fixes #8026 Signed-off-by: Paul Holzinger --- libpod/container_internal_linux.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 105623810..eff390e46 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -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 { -- cgit v1.2.3-54-g00ecf