Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libpod: Add checks to avoid nil pointer dereference if network setup fails #16645

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions libpod/container_internal_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ func (c *Container) reloadNetwork() error {
// Add an existing container's network jail
func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error {
nsCtr, err := c.runtime.state.Container(ctr)
c.runtime.state.UpdateContainer(nsCtr)
if err != nil {
return fmt.Errorf("retrieving dependency %s of container %s from state: %w", ctr, c.ID(), err)
}
g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetNS.Name)
c.runtime.state.UpdateContainer(nsCtr)
if nsCtr.state.NetNS != nil {
g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetNS.Name)
}
return nil
}

Expand All @@ -191,6 +193,14 @@ func openDirectory(path string) (fd int, err error) {

func (c *Container) addNetworkNamespace(g *generate.Generator) error {
if c.config.CreateNetNS {
if c.state.NetNS == nil {
// This should not happen since network setup
// errors should be propagated correctly from
// (*Runtime).createNetNS. Check for it anyway
// since it caused nil pointer dereferences in
// the past (see #16333).
return fmt.Errorf("Inconsistent state: c.config.CreateNetNS is set but c.state.NetNS is nil")
}
g.AddAnnotation("org.freebsd.parentJail", c.state.NetNS.Name)
}
return nil
Expand Down