8000 fix: resolve G115 integer overflow conversion warnings for Go 1.24.1 … · coder/coder@a4f441a · GitHub
[go: up one dir, main page]

Skip to content

Commit a4f441a

Browse files
committed
fix: resolve G115 integer overflow conversion warnings for Go 1.24.1 compatibility
1 parent 792b4b5 commit a4f441a

File tree

11 files changed

+47
-27
lines changed

11 files changed

+47
-27
lines changed

coderd/insights.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ func (api *API) insightsUserStatusCounts(rw http.ResponseWriter, r *http.Request
325325
rows, err := api.Database.GetUserStatusCounts(ctx, database.GetUserStatusCountsParams{
326326
StartTime: sixtyDaysAgo,
327327
EndTime: nextHourInLoc,
328-
Interval: int32(interval),
328+
// #nosec G115 - Interval value is small and fits in int32 (typically days or hours)
329+
Interval: int32(interval),
329330
})
330331
if err != nil {
331332
if httpapi.IsUnauthorizedError(err) {

coderd/members.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ func (api *API) paginatedMembers(rw http.ResponseWriter, r *http.Request) {
201201

202202
paginatedMemberRows, err := api.Database.PaginatedOrganizationMembers(ctx, database.PaginatedOrganizationMembersParams{
203203
OrganizationID: organization.ID,
204-
LimitOpt: int32(paginationParams.Limit),
205-
OffsetOpt: int32(paginationParams.Offset),
204+
// #nosec G115 - Pagination limits are small and fit in int32
205+
LimitOpt: int32(paginationParams.Limit),
206+
// #nosec G115 - Pagination offsets are small and fit in int32
207+
OffsetOpt: int32(paginationParams.Offset),
206208
})
207209
if httpapi.Is404Error(err) {
208210
httpapi.ResourceNotFound(rw)

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,8 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
19961996
DisplayApps: convertDisplayApps(prAgent.GetDisplayApps()),
19971997
InstanceMetadata: pqtype.NullRawMessage{},
19981998
ResourceMetadata: pqtype.NullRawMessage{},
1999-
DisplayOrder: int32(prAgent.Order),
1999+
// #nosec G115 - Order represents a display order value that's always small and fits in int32
2000+
DisplayOrder: int32(prAgent.Order),
20002001
})
20012002
if err != nil {
20022003
return xerrors.Errorf("insert agent: %w", err)
@@ -2011,7 +2012,8 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
20112012
Key: md.Key,
20122013
Timeout: md.Timeout,
20132014
Interval: md.Interval,
2014-
DisplayOrder: int32(md.Order),
2015+
// #nosec G115 - Order represents a display order value that's always small and fits in int32
2016+
DisplayOrder: int32(md.Order),
20152017
}
20162018
err := db.InsertWorkspaceAgentMetadata(ctx, p)
20172019
if err != nil {
@@ -2194,9 +2196,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
21942196
HealthcheckInterval: app.Healthcheck.Interval,
21952197
HealthcheckThreshold: app.Healthcheck.Threshold,
21962198
Health: health,
2197-
DisplayOrder: int32(app.Order),
2198-
Hidden: app.Hidden,
2199-
OpenIn: openIn,
2199+
// #nosec G115 - Order represents a display order value that's always small and fits in int32
2200+
DisplayOrder: int32(app.Order),
2201+
Hidden: app.Hidden,
2202+
OpenIn: openIn,
22002203
})
22012204
if err != nil {
22022205
return xerrors.Errorf("insert app: %w", err)

coderd/templateversions.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,11 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
843843
versions, err := store.GetTemplateVersionsByTemplateID(ctx, database.GetTemplateVersionsByTemplateIDParams{
844844
TemplateID: template.ID,
845845
AfterID: paginationParams.AfterID,
846-
LimitOpt: int32(paginationParams.Limit),
847-
OffsetOpt: int32(paginationParams.Offset),
848-
Archived: archiveFilter,
846+
// #nosec G115 - Pagination limits are small and fit in int32
847+
LimitOpt: int32(paginationParams.Limit),
848+
// #nosec G115 - Pagination offsets are small and fit in int32
849+
OffsetOpt: int32(paginationParams.Offset),
850+
Archived: archiveFilter,
849851
})
850852
if errors.Is(err, sql.ErrNoRows) {
851853
httpapi.Write(ctx, rw, http.StatusOK, apiVersions)

coderd/users.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ func (api *API) GetUsers(rw http.ResponseWriter, r *http.Request) ([]database.Us
306306
CreatedAfter: params.CreatedAfter,
307307
CreatedBefore: params.CreatedBefore,
308308
GithubComUserID: params.GithubComUserID,
309-
OffsetOpt: int32(paginationParams.Offset),
310-
LimitOpt: int32(paginationParams.Limit),
309+
// #nosec G115 - Pagination offsets are small and fit in int32
310+
OffsetOpt: int32(paginationParams.Offset),
311+
// #nosec G115 - Pagination limits are small and fit in int32
312+
LimitOpt: int32(paginationParams.Limit),
311313
})
312314
if err != nil {
313315
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{

coderd/workspaceagents.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,12 @@ func (api *API) patchWorkspaceAgentLogs(rw http.ResponseWriter, r *http.Request)
215215
}
216216

217217
logs, err := api.Database.InsertWorkspaceAgentLogs(ctx, database.InsertWorkspaceAgentLogsParams{
218-
AgentID: workspaceAgent.ID,
219-
CreatedAt: dbtime.Now(),
220-
Output: output,
221-
Level: level,
222-
LogSourceID: req.LogSourceID,
218+
AgentID: workspaceAgent.ID,
219+
CreatedAt: dbtime.Now(),
220+
Output: output,
221+
Level: level,
222+
LogSourceID: req.LogSourceID,
223+
// #nosec G115 - Log output length is limited and fits in int32
223224
OutputLength: int32(outputLength),
224225
})
225226
if err != nil {

coderd/workspacebuilds.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ func (api *API) workspaceBuilds(rw http.ResponseWriter, r *http.Request) {
161161
req := database.GetWorkspaceBuildsByWorkspaceIDParams{
162162
WorkspaceID: workspace.ID,
163163
AfterID: paginationParams.AfterID,
164-
OffsetOpt: int32(paginationParams.Offset),
165-
LimitOpt: int32(paginationParams.Limit),
166-
Since: dbtime.Time(since),
164+
// #nosec G115 - Pagination offsets are small and fit in int32
165+
OffsetOpt: int32(paginationParams.Offset),
166+
// #nosec G115 - Pagination limits are small and fit in int32
167+
LimitOpt: int32(paginationParams.Limit),
168+
Since: dbtime.Time(since),
167169
}
168170
workspaceBuilds, err = store.GetWorkspaceBuildsByWorkspaceID(ctx, req)
169171
if xerrors.Is(err, sql.ErrNoRows) {

enterprise/coderd/coderd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
529529
// We always want to run the replica manager even if we don't have DERP
530530
// enabled, since it's used to detect other coder servers for licensing.
531531
api.replicaManager, err = replicasync.New(ctx, options.Logger, options.Database, options.Pubsub, &replicasync.Options{
532-
ID: api.AGPL.ID,
533-
RelayAddress: options.DERPServerRelayAddress,
532+
ID: api.AGPL.ID,
533+
RelayAddress: options.DERPServerRelayAddress,
534+
// #nosec G115 - DERP region IDs are small and fit in int32
534535
RegionID: int32(options.DERPServerRegionID),
535536
TLSConfig: meshTLSConfig,
536537
UpdateInterval: options.ReplicaSyncUpdateInterval,

enterprise/coderd/groups.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (api *API) postGroupByOrganization(rw http.ResponseWriter, r *http.Request)
6161
DisplayName: req.DisplayName,
6262
OrganizationID: org.ID,
6363
AvatarURL: req.AvatarURL,
64+
// #nosec G115 - Quota allowance is small and fits in int32
6465
QuotaAllowance: int32(req.QuotaAllowance),
6566
})
6667
if database.IsUniqueViolation(err) {
@@ -218,6 +219,7 @@ func (api *API) patchGroup(rw http.ResponseWriter, r *http.Request) {
218219
updateGroupParams.Name = req.Name
219220
}
220221
if req.QuotaAllowance != nil {
222+
// #nosec G115 - Quota allowance is small and fits in int32
221223
updateGroupParams.QuotaAllowance = int32(*req.QuotaAllowance)
222224
}
223225
if req.DisplayName != nil {

enterprise/coderd/jfrog.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ func (api *API) postJFrogXrayScan(rw http.ResponseWriter, r *http.Request) {
3232
err := api.Database.UpsertJFrogXrayScanByWorkspaceAndAgentID(ctx, database.UpsertJFrogXrayScanByWorkspaceAndAgentIDParams{
3333
WorkspaceID: req.WorkspaceID,
3434
AgentID: req.AgentID,
35-
Critical: int32(req.Critical),
36-
High: int32(req.High),
37-
Medium: int32(req.Medium),
38-
ResultsUrl: req.ResultsURL,
35+
// #nosec G115 - Vulnerability counts are small and fit in int32
36+
Critical: int32(req.Critical),
37+
// #nosec G115 - Vulnerability counts are small and fit in int32
38+
High: int32(req.High),
39+
// #nosec G115 - Vulnerability counts are small and fit in int32
40+
Medium: int32(req.Medium),
41+
ResultsUrl: req.ResultsURL,
3942
})
4043
if httpapi.Is404Error(err) {
4144
httpapi.ResourceNotFound(rw)

tailnet/conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type TelemetrySink interface {
132132
// NodeID creates a Tailscale NodeID from the last 8 bytes of a UUID. It ensures
133133
// the returned NodeID is always positive.
134134
func NodeID(uid uuid.UUID) tailcfg.NodeID {
135+
// #nosec G115 - This is safe because the next lines ensure the ID is always positive
135136
id := int64(binary.BigEndian.Uint64(uid[8:]))
136137

137138
// ensure id is positive

0 commit comments

Comments
 (0)
0