Skip to content

Commit 39af2b0

Browse files
kinokopioclaude
andcommitted
fix: check json.Unmarshal errors in sa commands
Fix golangci-lint errcheck warnings for unchecked errors - Add error checking for json.Unmarshal in list.go (2 occurrences) - Add error checking for json.Unmarshal in scan.go (2 occurrences) Use zero values as fallback when unmarshaling fails All golangci-lint errors are now resolved. Co-authored-by: Kinopio <125463022+kinopio1101@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6a9fbcc commit 39af2b0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

internal/console/commands/sa/list.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,12 @@ func (c *ListCmd) Execute(sess *session.Session, args []string) error {
6666

6767
var secFlags types.SASecurityFlags
6868
var perms []types.SAPermission
69-
json.Unmarshal([]byte(sa.SecurityFlags), &secFlags)
70-
json.Unmarshal([]byte(sa.Permissions), &perms)
69+
if err := json.Unmarshal([]byte(sa.SecurityFlags), &secFlags); err != nil {
70+
secFlags = types.SASecurityFlags{}
71+
}
72+
if err := json.Unmarshal([]byte(sa.Permissions), &perms); err != nil {
73+
perms = []types.SAPermission{}
74+
}
7175

7276
rows = append(rows, output.SARow{
7377
Risk: formatRiskLabel(p, config.RiskLevel(sa.RiskLevel), sa.IsClusterAdmin),

internal/console/commands/sa/scan.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ func (c *ScanCmd) saveResults(sess *session.Session, results []SATokenResult) in
260260

261261
func (c *ScanCmd) mergeExistingRecord(existing *types.ServiceAccountRecord, result SATokenResult) {
262262
var pods []types.SAPodInfo
263-
json.Unmarshal([]byte(existing.Pods), &pods)
263+
if err := json.Unmarshal([]byte(existing.Pods), &pods); err != nil {
264+
pods = []types.SAPodInfo{}
265+
}
264266
pods = append(pods, types.SAPodInfo{
265267
Name: result.PodName,
266268
Namespace: result.Namespace,
@@ -270,7 +272,9 @@ func (c *ScanCmd) mergeExistingRecord(existing *types.ServiceAccountRecord, resu
270272
existing.Pods = string(podsJSON)
271273

272274
var existingFlags types.SASecurityFlags
273-
json.Unmarshal([]byte(existing.SecurityFlags), &existingFlags)
275+
if err := json.Unmarshal([]byte(existing.SecurityFlags), &existingFlags); err != nil {
276+
existingFlags = types.SASecurityFlags{}
277+
}
274278
existingFlags.Privileged = existingFlags.Privileged || result.SecurityFlags.Privileged
275279
existingFlags.AllowPrivilegeEscalation = existingFlags.AllowPrivilegeEscalation || result.SecurityFlags.AllowPrivilegeEscalation
276280
existingFlags.HasHostPath = existingFlags.HasHostPath || result.SecurityFlags.HasHostPath

0 commit comments

Comments
 (0)