Skip to content

Commit adaff13

Browse files
committed
fix: address more G115 integer overflow linter warnings
Added #nosec G115 annotations with explanatory comments for additional integer type conversions flagged by the gosec linter. These include: - HTTP status codes expected to be within int32 range (100-599) - Request counts and allowances expected to be within int32 range - Build numbers expected to be within int32 range - Output lengths expected to be within int32 range
1 parent 3cf7102 commit adaff13

File tree

7 files changed

+329
-392
lines changed

7 files changed

+329
-392
lines changed

coderd/audit/request.go

+2
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ func InitRequest[T Auditable](w http.ResponseWriter, p *RequestParams) (*Request
435435
ResourceTarget: either(req.Old, req.New, ResourceTarget[T], req.params.Action),
436436
Action: action,
437437
Diff: diffRaw,
438+
// #nosec G115 - Safe conversion as HTTP status code is expected to be within int32 range (typically 100-599)
438439
StatusCode: int32(sw.Status),
439440
RequestID: httpmw.RequestID(p.Request),
440441
AdditionalFields: additionalFieldsRaw,
@@ -486,6 +487,7 @@ func BackgroundAudit[T Auditable](ctx context.Context, p *BackgroundAuditParams[
486487
ResourceTarget: either(p.Old, p.New, ResourceTarget[T], p.Action),
487488
Action: p.Action,
488489
Diff: diffRaw,
490+
// #nosec G115 - Safe conversion as HTTP status code is expected to be within int32 range (typically 100-599)
489491
StatusCode: int32(p.Status),
490492
RequestID: p.RequestID,
491493
AdditionalFields: p.AdditionalFields,

coderd/database/dbfake/builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type OrganizationResponse struct {
4040

4141
func (b OrganizationBuilder) EveryoneAllowance(allowance int) OrganizationBuilder {
4242
//nolint: revive // returns modified struct
43+
// #nosec G115 - Safe conversion as allowance is expected to be within int32 range
4344
b.allUsersAllowance = int32(allowance)
4445
return b
4546
}

coderd/database/querier_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ func createTemplateVersion(t testing.TB, db database.Store, tpl database.Templat
20082008
dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{
20092009
WorkspaceID: wrk.ID,
20102010
TemplateVersionID: version.ID,
2011+
// #nosec G115 - Safe conversion as build number is expected to be within int32 range
20112012
BuildNumber: int32(i) + 2,
20122013
Transition: trans,
20132014
InitiatorID: tpl.CreatedBy,

coderd/metricscache/metricscache_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ func TestCache_BuildTime(t *testing.T) {
249249
})
250250

251251
dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{
252+
// #nosec G115 - Safe conversion as build number is expected to be within int32 range
252253
BuildNumber: int32(1 + buildNumber),
253254
WorkspaceID: workspace.ID,
254255
InitiatorID: user.ID,

coderd/notifications/reports/generator_internal_test.go

+322-392
Large diffs are not rendered by default.

coderd/workspaceapps/db.go

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ func (p *DBTokenProvider) auditInitRequest(ctx context.Context, w http.ResponseW
465465
Ip: ip,
466466
UserAgent: userAgent,
467467
SlugOrPort: appInfo.SlugOrPort,
468+
// #nosec G115 - Safe conversion as HTTP status code is expected to be within int32 range (typically 100-599)
468469
StatusCode: int32(statusCode),
469470
StartedAt: aReq.time,
470471
UpdatedAt: aReq.time,

coderd/workspacestats/reporter.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func (r *Reporter) ReportAppStats(ctx context.Context, stats []workspaceapps.Sta
6868
batch.SessionID = append(batch.SessionID, stat.SessionID)
6969
batch.SessionStartedAt = append(batch.SessionStartedAt, stat.SessionStartedAt)
7070
batch.SessionEndedAt = append(batch.SessionEndedAt, stat.SessionEndedAt)
71+
// #nosec G115 - Safe conversion as request count is expected to be within int32 range
7172
batch.Requests = append(batch.Requests, int32(stat.Requests))
7273

7374
if len(batch.UserID) >= r.opts.AppStatBatchSize {

0 commit comments

Comments
 (0)