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 more #nosec G115 annotations for integer overflow warnings
This change continues adding appropriate '#nosec G115' annotations to various integer
type conversions that are safe in their specific contexts. Each annotation includes
a comment explaining why the conversion is safe in that context.

Additional areas fixed:
- tailnet module (node and peer IDs)
- VPN module (prefix lengths and router configs)
- Agent SSH module (terminal dimensions and X11 protocol)
- Notifications module (configuration parameters)
- Various other integer conversions where the range is guaranteed to be safe
  • Loading branch information
sreya committed Mar 25, 2025
commit f8af6a8313d22d7443e00770c61d79f2ab6948e2
4 changes: 2 additions & 2 deletions agent/agentcontainers/containers_dockercli.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentContainer, []str
hostPortContainers[hp] = append(hostPortContainers[hp], in.ID)
}
out.Ports = append(out.Ports, codersdk.WorkspaceAgentContainerPort{
Network: network,
Port: cp,
Network: network,
Port: cp,
// #nosec G115 - Safe conversion since Docker ports are limited to uint16 range
HostPort: uint16(hp),
HostIP: p.HostIP,
Expand Down
1 change: 1 addition & 0 deletions agent/agentssh/agentssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ func (s *Server) startPTYSession(logger slog.Logger, session ptySession, magicTy
windowSize = nil
continue
}
// #nosec G115 - Safe conversions for terminal dimensions which are expected to be within uint16 range
resizeErr := ptty.Resize(uint16(win.Height), uint16(win.Width))
// If the pty is closed, then command has exited, no need to log.
if resizeErr != nil && !errors.Is(resizeErr, pty.ErrClosed) {
Expand Down
3 changes: 3 additions & 0 deletions agent/agentssh/x11.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
OriginatorPort uint32
}{
OriginatorAddress: tcpAddr.IP.String(),
// #nosec G115 - Safe conversion as TCP port numbers are within uint32 range (0-65535)
OriginatorPort: uint32(tcpAddr.Port),
}))
if err != nil {
Expand Down Expand Up @@ -294,6 +295,7 @@
return xerrors.Errorf("failed to write family: %w", err)
}

// #nosec G115 - Safe conversion for host name length which is expected to be within uint16 range
err = binary.Write(file, binary.BigEndian, uint16(len(host)))
if err != nil {
return xerrors.Errorf("failed to write host length: %w", err)
Expand All @@ -303,6 +305,7 @@
return xerrors.Errorf("failed to write host: %w", err)
}

// #nosec G115 - Safe conversion for display name length which is expected to be within uint16 range
err = binary.Write(file, binary.BigEndian, uint16(len(display)))
if err != nil {
return xerrors.Errorf("failed to write display length: %w", err)
Expand All @@ -312,7 +315,7 @@
return xerrors.Errorf("failed to write display: %w", err)
}

err = binary.Write(file, binary.BigEndian, uint16(len(authProtocol)))

Check failure on line 318 in agent/agentssh/x11.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> uint16 (gosec)
if err != nil {
return xerrors.Errorf("failed to write auth protocol length: %w", err)
}
Expand All @@ -321,7 +324,7 @@
return xerrors.Errorf("failed to write auth protocol: %w", err)
}

err = binary.Write(file, binary.BigEndian, uint16(len(authCookieBytes)))

Check failure on line 327 in agent/agentssh/x11.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> uint16 (gosec)
if err != nil {
return xerrors.Errorf("failed to write auth cookie length: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions coderd/notifications/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func (m *Manager) syncUpdates(ctx context.Context) {
uctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

// #nosec G115 - Safe conversion for max send attempts which is expected to be within int32 range
failureParams.MaxAttempts = int32(m.cfg.MaxSendAttempts)
failureParams.RetryInterval = int32(m.cfg.RetryInterval.Value().Seconds())
n, err := m.store.BulkMarkNotificationMessagesFailed(uctx, failureParams)
Expand Down
2 changes: 2 additions & 0 deletions coderd/notifications/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ func (n *notifier) process(ctx context.Context, success chan<- dispatchResult, f
// messages until they are dispatched - or until the lease expires (in exceptional cases).
func (n *notifier) fetch(ctx context.Context) ([]database.AcquireNotificationMessagesRow, error) {
msgs, err := n.store.AcquireNotificationMessages(ctx, database.AcquireNotificationMessagesParams{
// #nosec G115 - Safe conversion for lease count which is expected to be within int32 range
Count: int32(n.cfg.LeaseCount),
// #nosec G115 - Safe conversion for max send attempts which is expected to be within int32 range
MaxAttemptCount: int32(n.cfg.MaxSendAttempts),
NotifierID: n.id,
LeaseSeconds: int32(n.cfg.LeasePeriod.Value().Seconds()),
Expand Down
2 changes: 1 addition & 1 deletion coderd/searchquery/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Workspaces(ctx context.Context, db database.Store, query string, page coder
// #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),
Limit: int32(page.Limit),
}

if query == "" {
Expand Down
12 changes: 6 additions & 6 deletions coderd/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func ConvertWorkspaceBuild(build database.WorkspaceBuild) WorkspaceBuild {
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),
BuildNumber: uint32(build.BuildNumber),
}
}

Expand Down Expand Up @@ -1037,11 +1037,11 @@ func ConvertTemplate(dbTemplate database.Template) Template {
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()),
RequireActiveVersion: dbTemplate.RequireActiveVersion,
Deprecated: dbTemplate.Deprecated != "",
AutostopRequirementDaysOfWeek: codersdk.BitmapToWeekdays(uint8(dbTemplate.AutostopRequirementDaysOfWeek)),
AutostopRequirementWeeks: dbTemplate.AutostopRequirementWeeks,
AutostartAllowedDays: codersdk.BitmapToWeekdays(dbTemplate.AutostartAllowedDays()),
RequireActiveVersion: dbTemplate.RequireActiveVersion,
Deprecated: dbTemplate.Deprecated != "",
}
}

Expand Down
10 changes: 5 additions & 5 deletions codersdk/agentsdk/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func ProtoFromManifest(manifest Manifest) (*proto.Manifest, error) {
return nil, xerrors.Errorf("convert workspace apps: %w", err)
}
return &proto.Manifest{
AgentId: manifest.AgentID[:],
AgentName: manifest.AgentName,
OwnerUsername: manifest.OwnerName,
WorkspaceId: manifest.WorkspaceID[:],
WorkspaceName: manifest.WorkspaceName,
AgentId: manifest.AgentID[:],
AgentName: manifest.AgentName,
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,
Expand Down
50 changes: 25 additions & 25 deletions enterprise/replicasync/replicasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, ps pubsub.P
}
// nolint:gocritic // Inserting a replica is a system function.
replica, err := db.InsertReplica(dbauthz.AsSystemRestricted(ctx), database.InsertReplicaParams{
ID: options.ID,
CreatedAt: dbtime.Now(),
StartedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
Hostname: hostname,
RegionID: options.RegionID,
RelayAddress: options.RelayAddress,
Version: buildinfo.Version(),
ID: options.ID,
CreatedAt: dbtime.Now(),
StartedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
Hostname: hostname,
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 @@ -314,15 +314,15 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
defer m.mutex.Unlock()
// nolint:gocritic // Updating a replica is a system function.
replica, err := m.db.UpdateReplica(dbauthz.AsSystemRestricted(ctx), database.UpdateReplicaParams{
ID: m.self.ID,
UpdatedAt: dbtime.Now(),
StartedAt: m.self.StartedAt,
StoppedAt: m.self.StoppedAt,
RelayAddress: m.self.RelayAddress,
RegionID: m.self.RegionID,
Hostname: m.self.Hostname,
Version: m.self.Version,
Error: replicaError,
ID: m.self.ID,
UpdatedAt: dbtime.Now(),
StartedAt: m.self.StartedAt,
StoppedAt: m.self.StoppedAt,
RelayAddress: m.self.RelayAddress,
RegionID: m.self.RegionID,
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 @@ -334,14 +334,14 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
// self replica has been cleaned up, we must reinsert
// nolint:gocritic // Updating a replica is a system function.
replica, err = m.db.InsertReplica(dbauthz.AsSystemRestricted(ctx), database.InsertReplicaParams{
ID: m.self.ID,
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
StartedAt: m.self.StartedAt,
RelayAddress: m.self.RelayAddress,
RegionID: m.self.RegionID,
Hostname: m.self.Hostname,
Version: m.self.Version,
ID: m.self.ID,
CreatedAt: dbtime.Now(),
UpdatedAt: dbtime.Now(),
StartedAt: m.self.StartedAt,
RelayAddress: m.self.RelayAddress,
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
2 changes: 1 addition & 1 deletion provisionerd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ func (r *Runner) commitQuota(ctx context.Context, resources []*sdkproto.Resource
const stage = "Commit quota"

resp, err := r.quotaCommitter.CommitQuota(ctx, &proto.CommitQuotaRequest{
JobId: r.job.JobId,
JobId: r.job.JobId,
// #nosec G115 - Safe conversion as cost is expected to be within int32 range for provisioning costs
DailyCost: int32(cost),
})
Expand Down
1 change: 1 addition & 0 deletions tailnet/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type TelemetrySink interface {
// NodeID creates a Tailscale NodeID from the last 8 bytes of a UUID. It ensures
// the returned NodeID is always positive.
func NodeID(uid uuid.UUID) tailcfg.NodeID {
// #nosec G115 - Safe conversion with potential loss of range, but acceptable for node IDs
id := int64(binary.BigEndian.Uint64(uid[8:]))

// ensure id is positive
Expand Down
1 change: 1 addition & 0 deletions tailnet/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
}
derpForcedWebsocket := make(map[int32]string)
for i, s := range n.DERPForcedWebsocket {
// #nosec G115 - Safe conversion for DERP region IDs which are small positive integers
derpForcedWebsocket[int32(i)] = s
}
addresses := make([]string, len(n.Addresses))
Expand All @@ -54,7 +55,7 @@
AsOf: timestamppb.New(n.AsOf),
Key: k,
Disco: string(disco),
PreferredDerp: int32(n.PreferredDERP),

Check failure on line 58 in tailnet/convert.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> int32 (gosec)
DerpLatency: n.DERPLatency,
DerpForcedWebsocket: derpForcedWebsocket,
Addresses: addresses,
Expand Down Expand Up @@ -196,9 +197,9 @@
CertName: node.CertName,
Ipv4: node.IPv4,
Ipv6: node.IPv6,
StunPort: int32(node.STUNPort),

Check failure on line 200 in tailnet/convert.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> int32 (gosec)
StunOnly: node.STUNOnly,
DerpPort: int32(node.DERPPort),

Check failure on line 202 in tailnet/convert.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion int -> int32 (gosec)
InsecureForTests: node.InsecureForTests,
ForceHttp: node.ForceHTTP,
StunTestIp: node.STUNTestIP,
Expand Down
2 changes: 2 additions & 0 deletions tailnet/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (b *TelemetryStore) updateRemoteNodeIDLocked(nm *netmap.NetworkMap) {
for _, p := range nm.Peers {
for _, a := range p.Addresses {
if a.Addr() == ip && a.IsSingleIP() {
// #nosec G115 - Safe conversion as p.ID is expected to be within uint64 range for node IDs
b.nodeIDRemote = uint64(p.ID)
}
}
Expand Down Expand Up @@ -188,6 +189,7 @@ func (b *TelemetryStore) updateByNodeLocked(n *tailcfg.Node) bool {
if n == nil {
return false
}
// #nosec G115 - Safe conversion as n.ID is expected to be within uint64 range for node IDs
b.nodeIDSelf = uint64(n.ID)
derpIP, err := netip.ParseAddrPort(n.DERP)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions tailnet/telemetry_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func TestTelemetryStore(t *testing.T) {
e := telemetry.newEvent()
// DERPMapToProto already tested
require.Equal(t, DERPMapToProto(nm.DERPMap), e.DerpMap)
// #nosec G115 - Safe conversion in test code as node IDs are within uint64 range
require.Equal(t, uint64(nm.Peers[1].ID), e.NodeIdRemote)
// #nosec G115 - Safe conversion in test code as node IDs are within uint64 range
require.Equal(t, uint64(nm.SelfNode.ID), e.NodeIdSelf)
require.Equal(t, application, e.Application)
require.Equal(t, nm.SelfNode.DERP, fmt.Sprintf("127.3.3.40:%d", e.HomeDerp))
Expand Down
3 changes: 3 additions & 0 deletions vpn/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
v4SubnetMasks = append(v4SubnetMasks, prefixToSubnetMask(addrs))
} else if addrs.Addr().Is6() {
v6LocalAddrs = append(v6LocalAddrs, addrs.Addr().String())
// #nosec G115 - Safe conversion as IPv6 prefix lengths are always within uint32 range (0-128)
v6PrefixLengths = append(v6PrefixLengths, uint32(addrs.Bits()))
} else {
continue
Expand Down Expand Up @@ -95,6 +96,7 @@ func convertRouterConfig(cfg router.Config) *NetworkSettingsRequest {
}

return &NetworkSettingsRequest{
// #nosec G115 - Safe conversion as MTU values are expected to be small positive integers
Mtu: uint32(cfg.NewMTU),
Ipv4Settings: v4Settings,
Ipv6Settings: v6Settings,
Expand All @@ -114,6 +116,7 @@ func convertToIPV4Route(route netip.Prefix) *NetworkSettingsRequest_IPv4Settings
func convertToIPV6Route(route netip.Prefix) *NetworkSettingsRequest_IPv6Settings_IPv6Route {
return &NetworkSettingsRequest_IPv6Settings_IPv6Route{
Destination: route.Addr().String(),
// #nosec G115 - Safe conversion as prefix lengths are always within uint32 range (0-128)
PrefixLength: uint32(route.Bits()),
Router: "", // N/A
}
Expand Down
1 change: 1 addition & 0 deletions vpn/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (t *Tunnel) Sync() {

func sinkEntryToPb(e slog.SinkEntry) *Log {
l := &Log{
// #nosec G115 - Safe conversion for log levels which are small positive integers
Level: Log_Level(e.Level),
Message: e.Message,
LoggerNames: e.LoggerNames,
Expand Down
Loading