Skip to content

Commit b12cccf

Browse files
yuqi-zhangopenshift-cherrypick-robot
authored andcommitted
Add nil/null checks to image registry secret decode
The MCO pod can sometimes panic early on, seemingly with an empty docker config json. Not sure if it's the json null literal, or if the decode removed unknown fields to end up empty, so adding a check for both.
1 parent 73c8ce4 commit b12cccf

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/secrets/secrets.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,28 @@ func newImageRegistrySecretFromDockerConfigBytes(in []byte) (ImageRegistrySecret
186186
return nil, fmt.Errorf("empty dockerconfig bytes")
187187
}
188188

189+
// Check if the input is just the JSON null literal
190+
if bytes.TrimSpace(in) != nil && string(bytes.TrimSpace(in)) == "null" {
191+
return nil, fmt.Errorf("dockerconfig bytes contain JSON null")
192+
}
193+
189194
errs := []error{}
190195

191196
cfg, err := decodeDockerConfigJSONBytes(in)
192197
if err == nil {
198+
if cfg == nil {
199+
return nil, fmt.Errorf("decoded DockerConfigJSONBytes is nil")
200+
}
193201
return &imageRegistrySecretImpl{cfg: *cfg, isLegacyStyle: false}, nil
194202
}
195203

196204
errs = append(errs, err)
197205

198206
auths, err := decodeDockercfgBytes(in)
199207
if err == nil {
208+
if auths == nil {
209+
return nil, fmt.Errorf("decoded DockercfgBytes is nil")
210+
}
200211
return &imageRegistrySecretImpl{cfg: DockerConfigJSON{Auths: *auths}, isLegacyStyle: true}, nil
201212
}
202213

0 commit comments

Comments
 (0)