Skip to content

Commit ce66fd8

Browse files
authored
Merge pull request #5292 from openshift-cherrypick-robot/cherry-pick-5253-to-release-4.20
[release-4.20] OCPBUGS-61882: Add nil/null checks to image registry secret decode
2 parents 1e4bcd6 + b12cccf commit ce66fd8

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)