Fix a potential segfault during infra container create
I was seeing some segfaults where image config was being passed
as nil, causing a nil dereference segfault. Fix the apparent
cause and add some safety fencing to try and ensure it doesn't
happen again.
@@ -31,6 +31,12 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, imgID
isRootless := rootless.IsRootless()
entryCmd := []string{r.config.InfraCommand}
+ if config == nil {
+
+ }
+ // I've seen circumstances where config is being passed as nil.
+ // Let's err on the side of safety and make sure it's safe to use.
+ if config != nil {
// default to entrypoint in image if there is one
if len(config.Entrypoint) > 0 {
entryCmd = config.Entrypoint
@@ -44,6 +50,7 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, imgID
g.AddProcessEnv(nameValSlice[0], nameValSlice[1])
}
}
+ }
g.SetRootReadonly(true)
g.SetProcessArgs(entryCmd)
@@ -97,5 +104,5 @@ func (r *Runtime) createInfraContainer(ctx context.Context, p *Pod) (*Container,
imageName := newImage.Names()[0]
imageID := data.ID
- return r.makeInfraContainer(ctx, p, imageName, imageID, newImage.Config)
+ return r.makeInfraContainer(ctx, p, imageName, imageID, data.Config)
}
