From 9a10cefd18a3f19e49aa6ae5683d1bcea37bdc97 Mon Sep 17 00:00:00 2001 From: Doug Rabson Date: Wed, 18 Mar 2026 12:41:41 +0000 Subject: [PATCH] libpod: Don't dereference ctrSpec.Linux if it is nil This prevents a nil pointer crash when running network=host containers on a FreeBSD host using podman-remote. Fixes: #28289 Signed-off-by: Doug Rabson --- libpod/container.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libpod/container.go b/libpod/container.go index 68e22468063..ce29ac4e7a9 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -1459,18 +1459,20 @@ func (c *Container) NetworkMode() string { // If there is none, it's host networking. // If there is one and it has a path, it's "ns:". foundNetNS := false - for _, ns := range ctrSpec.Linux.Namespaces { - if ns.Type == spec.NetworkNamespace { - foundNetNS = true - if ns.Path != "" { - networkMode = fmt.Sprintf("ns:%s", ns.Path) - } else { - // We're making a network ns, but not - // configuring with Slirp or CNI. That - // means it's --net=none - networkMode = "none" + if ctrSpec.Linux != nil { + for _, ns := range ctrSpec.Linux.Namespaces { + if ns.Type == spec.NetworkNamespace { + foundNetNS = true + if ns.Path != "" { + networkMode = fmt.Sprintf("ns:%s", ns.Path) + } else { + // We're making a network ns, but not + // configuring with Slirp or CNI. That + // means it's --net=none + networkMode = "none" + } + break } - break } } if !foundNetNS {