Skip to content

Commit

Permalink
fix: handle int overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Victoremepunto committed Sep 12, 2024
1 parent e10c133 commit edc744e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
linters:
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errcheck
# https://golangci-lint.run/usage/linters/#enabled-by-default
# - errcheck
# - gosimple
# - govet
# - ineffassign
# - staticcheck
# - unused
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- revive
- staticcheck
- typecheck
- unused
- bodyclose
issues:
exclude-rules:
Expand Down
10 changes: 10 additions & 0 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
"math"

"github.com/RedHatInsights/clowder/controllers/cloud.redhat.com/errors"
crd "github.com/RedHatInsights/frontend-operator/api/v1alpha1"
Expand Down Expand Up @@ -53,6 +54,7 @@ func SetFrontendConditions(ctx context.Context, client client.Client, o *crd.Fro

condition.Type = crd.FrontendsReady
condition.LastTransitionTime = metav1.Now()
//FIXME: condition is always false
if err != nil {
condition.Message += err.Error()
condition.Reason = "Error"
Expand Down Expand Up @@ -112,7 +114,15 @@ func GetFrontendFigures(ctx context.Context, client client.Client, o *crd.Fronte
return crd.FrontendDeployments{}, "", errors.Wrap("count resources: ", err)
}

if results.Managed < math.MinInt32 || results.Managed > math.MaxInt32 {
return crd.FrontendDeployments{}, "", errors.NewClowderError("value out of range for int32")
}
deploymentStats.ManagedDeployments = int32(results.Managed)

Check failure on line 120 in controllers/status.go

View workflow job for this annotation

GitHub Actions / Lint

G115: integer overflow conversion int -> int32 (gosec)

if results.Ready < math.MinInt32 || results.Ready > math.MaxInt32 {
return crd.FrontendDeployments{}, "", errors.NewClowderError("value out of range for int32")
}
deploymentStats.ReadyDeployments = int32(results.Ready)

Check failure on line 125 in controllers/status.go

View workflow job for this annotation

GitHub Actions / Lint

G115: integer overflow conversion int -> int32 (gosec)

return deploymentStats, results.BrokenMessage, nil
}

0 comments on commit edc744e

Please sign in to comment.