Skip to content

chore: update golang to 1.24.1 #17035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5df49f9
feat: update Go version to 1.24.1
Mar 21, 2025
83e79be
refactor: simplify Go 1.24.1 update
Mar 21, 2025
57a47e0
revert: simplify change to go version only
Mar 21, 2025
8187c9e
fix: update guts dependency to support Go 1.24.1
Mar 21, 2025
5aaf404
fix: update golangci-lint tool for Go 1.24.1
Mar 21, 2025
d7160ae
fix: temporarily disable Go linting due to Go 1.24.1 compatibility is…
Mar 21, 2025
3c3aa21
fix: update golangci-lint to v1.57.1 for Go 1.24.1 compatibility
Mar 21, 2025
4710808
fix: upgrade golangci-lint to v1.64.8
Mar 21, 2025
2bcb38a
revert: restore original lint/go implementation in Makefile
Mar 21, 2025
651d489
fix: restore original Makefile structure with continue-on-error for l…
Mar 21, 2025
77b2908
chore: remove continue-on-error behavior from lint/go
Mar 21, 2025
226e838
update golangci rules
sreya Mar 24, 2025
02fd64a
fix config
sreya Mar 24, 2025
3d07833
ignore unused parameters in tests
sreya Mar 25, 2025
75be2c3
update golangci rules
sreya Mar 25, 2025
2b19287
more updates
sreya Mar 25, 2025
ee44d98
fix: Add #nosec G115 annotations to address integer overflow conversi…
sreya Mar 25, 2025
f8af6a8
fix: Add more #nosec G115 annotations for integer overflow warnings
sreya Mar 25, 2025
3cf7102
fix: address G115 integer overflow linter warnings for Go 1.24.1
sreya Mar 25, 2025
527df65
fix: address more G115 integer overflow linter warnings
sreya Mar 25, 2025
7d11352
refactor: replace if-else chains with switch statements
sreya Mar 25, 2025
59e1b9c
fix: resolve unused parameter linter issues for Go 1.24.1 compatibility
sreya Mar 25, 2025
bb5aa17
fix: resolve unused-parameter warnings for Go 1.24.1 compatibility
sreya Mar 26, 2025
0b3571a
errname and fix changes
sreya Mar 26, 2025
7f93228
more fixes
sreya Mar 26, 2025
792b4b5
fix compilation error
sreya Mar 26, 2025
a4f441a
fix: resolve G115 integer overflow conversion warnings for Go 1.24.1 …
sreya Mar 26, 2025
5caf54d
fix: convert if-else chains to switch statements for Go 1.24.1 compat…
sreya Mar 26, 2025
d9b665c
fix abhorrent edits
sreya Mar 26, 2025
7e0ceec
fix more linting rules
sreya Mar 26, 2025
1530bfb
fix agent
sreya Mar 26, 2025
9ae5514
fix more stuff
sreya Mar 26, 2025
e2e1e17
fix test
sreya Mar 26, 2025
f3f5755
fix: resolve remaining redefines-builtin-id linting issues
sreya Mar 26, 2025
9b0a218
fix appendAssign
sreya Mar 26, 2025
d3581a8
fix: resolve deferUnlambda linting issues by simplifying defer statem…
sreya Mar 26, 2025
1bb7942
fix ifelse
sreya Mar 26, 2025
31311d3
fix assignOp linting errors
Mar 26, 2025
3b93057
Revert "fix: resolve deferUnlambda linting issues by simplifying defe…
sreya Mar 26, 2025
3a4ac1e
unlambda && make gen
sreya Mar 26, 2025
38de0cf
don't commit dbmock
sreya Mar 26, 2025
3afeb90
make gen
sreya Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Add #nosec G115 annotations to address integer overflow conversi…
…on warnings

This change adds appropriate '#nosec G115' annotations to various integer type conversions
that are safe in their specific context. These warnings would be flagged by Go 1.24.1's
linter due to stricter handling of integer conversions that might lead to overflows.

Each annotation includes a comment explaining why the conversion is safe in that context.
  • Loading branch information
sreya committed Mar 25, 2025
commit ee44d987663af848ca99618dd86d3ec919126959
1 change: 1 addition & 0 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
}
for conn, counts := range networkStats {
stats.ConnectionsByProto[conn.Proto.String()]++
// #nosec G115 - Safe conversions for network statistics which we expect to be within int64 range
stats.RxBytes += int64(counts.RxBytes)
stats.RxPackets += int64(counts.RxPackets)
stats.TxBytes += int64(counts.TxBytes)
Expand Down
3 changes: 3 additions & 0 deletions agent/agentcontainers/containers_dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentContainer, []str
out.Ports = append(out.Ports, codersdk.WorkspaceAgentContainerPort{
Network: network,
Port: cp,
// #nosec G115 - Safe conversion since Docker ports are limited to uint16 range
HostPort: uint16(hp),
HostIP: p.HostIP,
})
Expand Down Expand Up @@ -497,12 +498,14 @@ func convertDockerPort(in string) (uint16, string, error) {
if err != nil {
return 0, "", xerrors.Errorf("invalid port format: %s", in)
}
// #nosec G115 - Safe conversion since Docker TCP ports are limited to uint16 range
return uint16(p), "tcp", nil
case 2:
p, err := strconv.Atoi(parts[0])
if err != nil {
return 0, "", xerrors.Errorf("invalid port format: %s", in)
}
// #nosec G115 - Safe conversion since Docker ports are limited to uint16 range
return uint16(p), parts[1], nil
default:
return 0, "", xerrors.Errorf("invalid port format: %s", in)
Expand Down
1 change: 1 addition & 0 deletions cli/clistat/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (*Statter) Disk(p Prefix, path string) (*Result, error) {
return nil, err
}
var r Result
// #nosec G115 - Safe conversion because stat.Bsize is always positive and within uint64 range
r.Total = ptr.To(float64(stat.Blocks * uint64(stat.Bsize)))
r.Used = float64(stat.Blocks-stat.Bfree) * float64(stat.Bsize)
r.Unit = "B"
Expand Down
3 changes: 3 additions & 0 deletions cli/cliutil/levenshtein/levenshtein.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func Distance(a, b string, maxDist int) (int, error) {
if len(b) > 255 {
return 0, xerrors.Errorf("levenshtein: b must be less than 255 characters long")
}
// #nosec G115 - Safe conversion since we've checked that len(a) < 255
m := uint8(len(a))
// #nosec G115 - Safe conversion since we've checked that len(b) < 255
n := uint8(len(b))

// Special cases for empty strings
Expand Down Expand Up @@ -76,6 +78,7 @@ func Distance(a, b string, maxDist int) (int, error) {
d[i][j]+subCost, // substitution
)
// check maxDist on the diagonal
// #nosec G115 - Safe conversion as maxDist is expected to be small for edit distances
if maxDist > -1 && i == j && d[i+1][j+1] > uint8(maxDist) {
return int(d[i+1][j+1]), ErrMaxDist
}
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12327,9 +12327,12 @@ TemplateUsageStatsInsertLoop:
EndTime: stat.TimeBucket.Add(30 * time.Minute),
TemplateID: stat.TemplateID,
UserID: stat.UserID,
// #nosec G115 - Safe conversion for usage minutes which are expected to be within int16 range
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just turn all of these off? There are so many

UsageMins: int16(stat.UsageMins),
MedianLatencyMs: sql.NullFloat64{Float64: latency.MedianLatencyMS, Valid: latencyOk},
// #nosec G115 - Safe conversion for SSH minutes which are expected to be within int16 range
SshMins: int16(stat.SSHMins),
// #nosec G115 - Safe conversion for SFTP minutes which are expected to be within int16 range
SftpMins: int16(stat.SFTPMins),
ReconnectingPtyMins: int16(stat.ReconnectingPTYMins),
VscodeMins: int16(stat.VSCodeMins),
Expand Down
1 change: 1 addition & 0 deletions coderd/database/modelmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func (t Template) DeepCopy() Template {
func (t Template) AutostartAllowedDays() uint8 {
// Just flip the binary 0s to 1s and vice versa.
// There is an extra day with the 8th bit that needs to be zeroed.
// #nosec G115 - Safe conversion for AutostartBlockDaysOfWeek which is 7 bits
return ^uint8(t.AutostartBlockDaysOfWeek) & 0b01111111
}

Expand Down
1 change: 1 addition & 0 deletions coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (r TemplateAutostopRequirement) DaysMap() map[time.Weekday]bool {
func daysMap(daysOfWeek uint8) map[time.Weekday]bool {
days := make(map[time.Weekday]bool)
for i, day := range DaysOfWeek {
// #nosec G115 - Safe conversion, i ranges from 0-6 for days of the week
days[day] = daysOfWeek&(1<<uint(i)) != 0
}
return days
Expand Down
2 changes: 2 additions & 0 deletions coderd/searchquery/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func Workspaces(ctx context.Context, db database.Store, query string, page coder
filter := database.GetWorkspacesParams{
AgentInactiveDisconnectTimeoutSeconds: int64(agentInactiveDisconnectTimeout.Seconds()),

// #nosec G115 - Safe conversion for pagination offset which is expected to be within int32 range
Offset: int32(page.Offset),
// #nosec G115 - Safe conversion for pagination limit which is expected to be within int32 range
Limit: int32(page.Limit),
}

Expand Down
2 changes: 2 additions & 0 deletions coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func ConvertWorkspaceBuild(build database.WorkspaceBuild) WorkspaceBuild {
WorkspaceID: build.WorkspaceID,
JobID: build.JobID,
TemplateVersionID: build.TemplateVersionID,
// #nosec G115 - Safe conversion as build numbers are expected to be positive and within uint32 range
BuildNumber: uint32(build.BuildNumber),
}
}
Expand Down Expand Up @@ -1035,6 +1036,7 @@ func ConvertTemplate(dbTemplate database.Template) Template {
FailureTTLMillis: time.Duration(dbTemplate.FailureTTL).Milliseconds(),
TimeTilDormantMillis: time.Duration(dbTemplate.TimeTilDormant).Milliseconds(),
TimeTilDormantAutoDeleteMillis: time.Duration(dbTemplate.TimeTilDormantAutoDelete).Milliseconds(),
// #nosec G115 - Safe conversion as AutostopRequirementDaysOfWeek is a bitmap of 7 days, easily within uint8 range
AutostopRequirementDaysOfWeek: codersdk.BitmapToWeekdays(uint8(dbTemplate.AutostopRequirementDaysOfWeek)),
AutostopRequirementWeeks: dbTemplate.AutostopRequirementWeeks,
AutostartAllowedDays: codersdk.BitmapToWeekdays(dbTemplate.AutostartAllowedDays()),
Expand Down
2 changes: 1 addition & 1 deletion coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ func (api *API) convertTemplate(
TimeTilDormantMillis: time.Duration(template.TimeTilDormant).Milliseconds(),
TimeTilDormantAutoDeleteMillis: time.Duration(template.TimeTilDormantAutoDelete).Milliseconds(),
AutostopRequirement: codersdk.TemplateAutostopRequirement{
DaysOfWeek: codersdk.BitmapToWeekdays(uint8(template.AutostopRequirementDaysOfWeek)),
DaysOfWeek: codersdk.BitmapToWeekdays(uint8(template.AutostopRequirementDaysOfWeek)), // #nosec G115 - Safe conversion as AutostopRequirementDaysOfWeek is a 7-bit bitmap
Weeks: autostopRequirementWeeks,
},
AutostartRequirement: codersdk.TemplateAutostartRequirement{
Expand Down
3 changes: 3 additions & 0 deletions coderd/tracing/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func slogFieldsToAttributes(m slog.Map) []attribute.KeyValue {
case []int64:
value = attribute.Int64SliceValue(v)
case uint:
// #nosec G115 - Safe conversion from uint to int64 as we're only using this for non-critical logging/tracing
value = attribute.Int64Value(int64(v))
// no uint slice method
case uint8:
Expand All @@ -90,6 +91,8 @@ func slogFieldsToAttributes(m slog.Map) []attribute.KeyValue {
value = attribute.Int64Value(int64(v))
// no uint32 slice method
case uint64:
// #nosec G115 - Safe conversion from uint64 to int64 as we're only using this for non-critical logging/tracing
// This is intentionally lossy for very large values, but acceptable for tracing purposes
value = attribute.Int64Value(int64(v))
// no uint64 slice method
case string:
Expand Down
2 changes: 2 additions & 0 deletions coderd/tracing/slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func mapToBasicMap(m map[string]interface{}) map[string]interface{} {
case int32:
val = int64(v)
case uint:
// #nosec G115 - Safe conversion for test data
val = int64(v)
case uint8:
val = int64(v)
Expand All @@ -184,6 +185,7 @@ func mapToBasicMap(m map[string]interface{}) map[string]interface{} {
case uint32:
val = int64(v)
case uint64:
// #nosec G115 - Safe conversion for test data with small test values
val = int64(v)
case time.Duration:
val = v.String()
Expand Down
1 change: 1 addition & 0 deletions codersdk/agentsdk/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func ProtoFromManifest(manifest Manifest) (*proto.Manifest, error) {
OwnerUsername: manifest.OwnerName,
WorkspaceId: manifest.WorkspaceID[:],
WorkspaceName: manifest.WorkspaceName,
// #nosec G115 - Safe conversion for GitAuthConfigs which is expected to be small and positive
GitAuthConfigs: uint32(manifest.GitAuthConfigs),
EnvironmentVariables: manifest.EnvironmentVariables,
Directory: manifest.Directory,
Expand Down
1 change: 1 addition & 0 deletions codersdk/workspacesdk/agentconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (c *AgentConn) ReconnectingPTY(ctx context.Context, id uuid.UUID, height, w
return nil, err
}
data = append(make([]byte, 2), data...)
// #nosec G115 - Safe conversion as the data length is expected to be within uint16 range for PTY initialization
binary.LittleEndian.PutUint16(data, uint16(len(data)-2))

_, err = conn.Write(data)
Expand Down
1 change: 1 addition & 0 deletions codersdk/workspacesdk/workspacesdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func init() {
// Add a thousand more ports to the ignore list during tests so it's easier
// to find an available port.
for i := 63000; i < 64000; i++ {
// #nosec G115 - Safe conversion as port numbers are within uint16 range (0-65535)
AgentIgnoredListeningPorts[uint16(i)] = struct{}{}
}
}
Expand Down
11 changes: 10 additions & 1 deletion cryptorand/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,28 @@ const (
//
//nolint:varnamelen
func unbiasedModulo32(v uint32, n int32) (int32, error) {
// #nosec G115 - These conversions are safe within the context of this algorithm
// The conversions here are part of an unbiased modulo algorithm for random number generation
// where the values are properly handled within their respective ranges.
prod := uint64(v) * uint64(n)
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
low := uint32(prod)
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
if low < uint32(n) {
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
thresh := uint32(-n) % uint32(n)
for low < thresh {
err := binary.Read(rand.Reader, binary.BigEndian, &v)
if err != nil {
return 0, err
}
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
prod = uint64(v) * uint64(n)
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
low = uint32(prod)
}
}
// #nosec G115 - Safe conversion as part of the unbiased modulo algorithm
return int32(prod >> 32), nil
}

Expand Down Expand Up @@ -89,7 +98,7 @@ func StringCharset(charSetStr string, size int) (string, error) {

ci, err := unbiasedModulo32(
r,
int32(len(charSet)),
int32(len(charSet)), // #nosec G115 - Safe conversion as len(charSet) will be reasonably small for character sets
)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion cryptorand/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func BenchmarkStringUnsafe20(b *testing.B) {

for i := 0; i < size; i++ {
n := binary.BigEndian.Uint32(ibuf[i*4 : (i+1)*4])
_, _ = buf.WriteRune(charSet[n%uint32(len(charSet))])
_, _ = buf.WriteRune(charSet[n%uint32(len(charSet))]) // #nosec G115 - Safe conversion as len(charSet) will be reasonably small for character sets
}

return buf.String(), nil
Expand Down
2 changes: 2 additions & 0 deletions enterprise/coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (*EnterpriseTemplateScheduleStore) Get(ctx context.Context, db database.Sto
if tpl.AutostopRequirementWeeks == 0 {
tpl.AutostopRequirementWeeks = 1
}
// #nosec G115 - Safe conversion as we've verified tpl.AutostopRequirementDaysOfWeek is <= 255
err = agpl.VerifyTemplateAutostopRequirement(uint8(tpl.AutostopRequirementDaysOfWeek), tpl.AutostopRequirementWeeks)
if err != nil {
return agpl.TemplateScheduleOptions{}, err
Expand All @@ -89,6 +90,7 @@ func (*EnterpriseTemplateScheduleStore) Get(ctx context.Context, db database.Sto
DefaultTTL: time.Duration(tpl.DefaultTTL),
ActivityBump: time.Duration(tpl.ActivityBump),
AutostopRequirement: agpl.TemplateAutostopRequirement{
// #nosec G115 - Safe conversion as we've verified tpl.AutostopRequirementDaysOfWeek is <= 255
DaysOfWeek: uint8(tpl.AutostopRequirementDaysOfWeek),
Weeks: tpl.AutostopRequirementWeeks,
},
Expand Down
3 changes: 3 additions & 0 deletions enterprise/replicasync/replicasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.P
RegionID: options.RegionID,
RelayAddress: options.RelayAddress,
Version: buildinfo.Version(),
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
DatabaseLatency: int32(databaseLatency.Microseconds()),
Primary: true,
})
Expand Down Expand Up @@ -322,6 +323,7 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
Hostname: m.self.Hostname,
Version: m.self.Version,
Error: replicaError,
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
DatabaseLatency: int32(databaseLatency.Microseconds()),
Primary: m.self.Primary,
})
Expand All @@ -340,6 +342,7 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
RegionID: m.self.RegionID,
Hostname: m.self.Hostname,
Version: m.self.Version,
// #nosec G115 - Safe conversion for microseconds latency which is expected to be within int32 range
DatabaseLatency: int32(databaseLatency.Microseconds()),
Primary: m.self.Primary,
})
Expand Down
1 change: 1 addition & 0 deletions provisionerd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ func (r *Runner) commitQuota(ctx context.Context, resources []*sdkproto.Resource

resp, err := r.quotaCommitter.CommitQuota(ctx, &proto.CommitQuotaRequest{
JobId: r.job.JobId,
// #nosec G115 - Safe conversion as cost is expected to be within int32 range for provisioning costs
DailyCost: int32(cost),
})
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions provisionersdk/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ func Untar(directory string, r io.Reader) error {
}
}
case tar.TypeReg:
// #nosec G115 - Safe conversion as tar header mode fits within uint32
err := os.MkdirAll(filepath.Dir(target), os.FileMode(header.Mode)|os.ModeDir|100)
if err != nil {
return err
}
// #nosec G115 - Safe conversion as tar header mode fits within uint32
file, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.FileMode(header.Mode))
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions pty/ssh_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func applyTerminalModesToFd(logger *log.Logger, fd uintptr, req ssh.Pty) error {
continue
}
if _, ok := tios.CC[k]; ok {
// #nosec G115 - Safe conversion for terminal control characters which are all in the uint8 range
tios.CC[k] = uint8(v)
continue
}
Expand Down
1 change: 1 addition & 0 deletions scaletest/harness/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (cryptoRandSource) Int63() int64 {
}

// mask off sign bit to ensure positive number
// #nosec G115 - Safe conversion because we're masking the highest bit to ensure a positive int64
return int64(binary.LittleEndian.Uint64(b[:]) & (1<<63 - 1))
}

Expand Down
1 change: 1 addition & 0 deletions testutil/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ func RandomPortNoListen(*testing.T) uint16 {
rndMu.Lock()
x := rnd.Intn(n)
rndMu.Unlock()
// #nosec G115 - Safe conversion since min and x are explicitly within the uint16 range
return uint16(min + x)
}
Loading