diff --git a/clientupdate/distsign/distsign_test.go b/clientupdate/distsign/distsign_test.go index 138007885..a8f25512d 100644 --- a/clientupdate/distsign/distsign_test.go +++ b/clientupdate/distsign/distsign_test.go @@ -344,7 +344,7 @@ func TestParseRootKey(t *testing.T) { desc: "invalid-PEM-tag", generate: func() ([]byte, []byte, error) { priv, pub, err := GenerateRootKey() - priv = bytes.Replace(priv, []byte("ROOT "), nil, -1) + priv = bytes.ReplaceAll(priv, []byte("ROOT "), nil) return priv, pub, err }, wantErr: true, @@ -402,7 +402,7 @@ func TestParseSigningKey(t *testing.T) { desc: "invalid-PEM-tag", generate: func() ([]byte, []byte, error) { priv, pub, err := GenerateSigningKey() - priv = bytes.Replace(priv, []byte("SIGNING "), nil, -1) + priv = bytes.ReplaceAll(priv, []byte("SIGNING "), nil) return priv, pub, err }, wantErr: true, diff --git a/cmd/derper/saved_syn_linux_test.go b/cmd/derper/saved_syn_linux_test.go index 78f3879d3..e4fc83452 100644 --- a/cmd/derper/saved_syn_linux_test.go +++ b/cmd/derper/saved_syn_linux_test.go @@ -192,7 +192,7 @@ func TestSavedSynListenerDisableRetry(t *testing.T) { t.Fatal("failed disable was not left pending") } monitor.update(ln, now.Add(time.Second), 0, nil) - if monitor.disabled || monitor.lastErrorLog != now { + if monitor.disabled || !monitor.lastErrorLog.Equal(now) { t.Fatal("failed retry changed disabled state or logged again") } replacement := newTestSavedSynListener(t) diff --git a/cmd/k8s-operator/egress-services.go b/cmd/k8s-operator/egress-services.go index 26bd22606..9cc784401 100644 --- a/cmd/k8s-operator/egress-services.go +++ b/cmd/k8s-operator/egress-services.go @@ -337,12 +337,9 @@ func (esr *egressSvcsReconciler) provision(ctx context.Context, proxyGroupName s } var healthCheckPort int32 = defaultLocalAddrPort - for { - if !slices.ContainsFunc(svc.Spec.Ports, func(p corev1.ServicePort) bool { - return p.Port == healthCheckPort - }) { - break - } + for slices.ContainsFunc(svc.Spec.Ports, func(p corev1.ServicePort) bool { + return p.Port == healthCheckPort + }) { healthCheckPort++ if healthCheckPort > 10002 { return nil, false, fmt.Errorf("unable to find a free port for internal health check in range [9002, 10002]") diff --git a/cmd/k8s-operator/operator_test.go b/cmd/k8s-operator/operator_test.go index 18a5e1847..b43f6d3e3 100644 --- a/cmd/k8s-operator/operator_test.go +++ b/cmd/k8s-operator/operator_test.go @@ -31,7 +31,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "tailscale.com/ipn" - "tailscale.com/k8s-operator/apis/v1alpha1" tsapi "tailscale.com/k8s-operator/apis/v1alpha1" "tailscale.com/k8s-operator/reconciler/tailscaled" "tailscale.com/k8s-operator/tsclient" @@ -1226,7 +1225,7 @@ func TestServiceProxyClassAnnotation(t *testing.T) { Spec: tsapi.ProxyClassSpec{ StatefulSet: &tsapi.StatefulSet{ Pod: &tsapi.Pod{ - TailscaleContainer: &v1alpha1.Container{ + TailscaleContainer: &tsapi.Container{ ImagePullPolicy: corev1.PullIfNotPresent, }, }, @@ -1241,7 +1240,7 @@ func TestServiceProxyClassAnnotation(t *testing.T) { Spec: tsapi.ProxyClassSpec{ StatefulSet: &tsapi.StatefulSet{ Pod: &tsapi.Pod{ - TailscaleContainer: &v1alpha1.Container{ + TailscaleContainer: &tsapi.Container{ ImagePullPolicy: corev1.PullAlways, }, }, diff --git a/cmd/natc/ippool/consensusippool_test.go b/cmd/natc/ippool/consensusippool_test.go index fe42b2b22..1578e67d1 100644 --- a/cmd/natc/ippool/consensusippool_test.go +++ b/cmd/natc/ippool/consensusippool_test.go @@ -181,7 +181,7 @@ func TestConsensusPoolApplyMarkLastUsed(t *testing.T) { if !ok { t.Fatal("expected wherewhen to be found") } - if ww.LastUsed != time1 { + if !ww.LastUsed.Equal(time1) { t.Fatalf("expected %s, got %s", time1, ww.LastUsed) } if ww.Domain != domain { @@ -198,7 +198,7 @@ func TestConsensusPoolApplyMarkLastUsed(t *testing.T) { if !ok { t.Fatal("expected wherewhen to be found") } - if ww.LastUsed != time2 { + if !ww.LastUsed.Equal(time2) { t.Fatalf("expected %s, got %s", time2, ww.LastUsed) } if ww.Domain != domain { diff --git a/cmd/sniproxy/handlers_test.go b/cmd/sniproxy/handlers_test.go index ad0637421..5a6343517 100644 --- a/cmd/sniproxy/handlers_test.go +++ b/cmd/sniproxy/handlers_test.go @@ -111,7 +111,7 @@ c9ef5e540d8d6f007789a7acf9f5f16f bf6a1907a6782ed02b` func fakeSNIHeader() []byte { - b, err := hex.DecodeString(strings.Replace(tlsStart, "\n", "", -1)) + b, err := hex.DecodeString(strings.ReplaceAll(tlsStart, "\n", "")) if err != nil { panic(err) } diff --git a/cmd/tailscale/cli/tailnet-lock.go b/cmd/tailscale/cli/tailnet-lock.go index e90799772..018b3d32c 100644 --- a/cmd/tailscale/cli/tailnet-lock.go +++ b/cmd/tailscale/cli/tailnet-lock.go @@ -671,7 +671,7 @@ func nlDescribeUpdate(update ipnstate.TailnetLockUpdate, color bool) (string, er case tka.AUMUpdateKey.String(): fmt.Fprintf(&stanza, "KeyID: tlpub:%x\n", aum.KeyID) if aum.Votes != nil { - fmt.Fprintf(&stanza, "Votes: %d\n", aum.Votes) + fmt.Fprintf(&stanza, "Votes: %d\n", *aum.Votes) } if aum.Meta != nil { fmt.Fprintf(&stanza, "Metadata: %+v\n", aum.Meta) diff --git a/cmd/tsconnect/build.go b/cmd/tsconnect/build.go index 3fdbba14c..3bab10250 100644 --- a/cmd/tsconnect/build.go +++ b/cmd/tsconnect/build.go @@ -51,8 +51,8 @@ func runBuild() { log.Fatalf("Cannot write metadata: %v", err) } - if er := precompressDist(*fastCompression); err != nil { - log.Fatalf("Cannot precompress resources: %v", er) + if err := precompressDist(*fastCompression); err != nil { + log.Fatalf("Cannot precompress resources: %v", err) } } diff --git a/cmd/tsconnect/termwriter/termwriter.go b/cmd/tsconnect/termwriter/termwriter.go index f4b992ffb..d1893ea88 100644 --- a/cmd/tsconnect/termwriter/termwriter.go +++ b/cmd/tsconnect/termwriter/termwriter.go @@ -43,7 +43,7 @@ func (w *Writer) Write(p []byte) (n int, err error) { w.pending = bytes.Clone(buf[end:]) if end > 0 { - r := bytes.Replace(buf[:end], []byte("\n"), []byte("\n\r"), -1) + r := bytes.ReplaceAll(buf[:end], []byte("\n"), []byte("\n\r")) w.write(string(r)) } return len(p), nil diff --git a/ipn/desktop/sessions_windows.go b/ipn/desktop/sessions_windows.go index 7d51900f9..d23f5d25f 100644 --- a/ipn/desktop/sessions_windows.go +++ b/ipn/desktop/sessions_windows.go @@ -488,12 +488,15 @@ func (sw *sessionWatcher) setHandle(hwnd windows.HWND) error { func sessionWatcherByHandle(hwnd windows.HWND) *sessionWatcher { val, _ := getWindowLongPtr(hwnd, _GWLP_USERDATA) + //lint:ignore unsafeptr The pointer was stored by setHandle and sw is kept alive by its owner. return (*sessionWatcher)(unsafe.Pointer(val)) } func sessionWatcherWndProc(hWnd windows.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) { if msg == _WM_NCCREATE { + //lint:ignore unsafeptr For WM_NCCREATE, lParam points to a CREATESTRUCT. cs := (*_CREATESTRUCT)(unsafe.Pointer(lParam)) + //lint:ignore unsafeptr CreateParams is the sessionWatcher passed to CreateWindowEx. sw := (*sessionWatcher)(unsafe.Pointer(cs.CreateParams)) if sw == nil { return 0 diff --git a/net/dns/resolver/negative_cache_apple_test.go b/net/dns/resolver/negative_cache_apple_test.go index 37bd1b5b0..d989e7c1a 100644 --- a/net/dns/resolver/negative_cache_apple_test.go +++ b/net/dns/resolver/negative_cache_apple_test.go @@ -105,7 +105,7 @@ func TestNegativeCacheUpdateDuringQuery(t *testing.T) { {name: "A", typ: dns.TypeA}, {name: "AAAA", typ: dns.TypeAAAA}, {name: "PTR", typ: dns.TypePTR}, - {name: "unrelated update", typ: dns.TypeA, stillMissing: true}, + {name: "unrelated_update", typ: dns.TypeA, stillMissing: true}, {name: "reset", typ: dns.TypeA, reset: true}, } { t.Run(tt.name, func(t *testing.T) { @@ -184,10 +184,10 @@ func TestCheckCachedDNS(t *testing.T) { {name: "recent", query: "server.test.net.", age: negativeCacheLifetime - time.Nanosecond, want: true}, {name: "expired", query: "server.test.net.", age: negativeCacheLifetime}, {name: "subdomain", query: "foo.server.test.net.", subdomains: true, want: true}, - {name: "nested subdomain", query: "foo.bar.server.test.net.", subdomains: true, want: true}, - {name: "no subdomain capability", query: "foo.server.test.net."}, - {name: "label boundary", query: "foo.otherserver.test.net.", subdomains: true}, - {name: "profile reset", query: "server.test.net.", reset: true}, + {name: "nested_subdomain", query: "foo.bar.server.test.net.", subdomains: true, want: true}, + {name: "no_subdomain_capability", query: "foo.server.test.net."}, + {name: "label_boundary", query: "foo.otherserver.test.net.", subdomains: true}, + {name: "profile_reset", query: "server.test.net.", reset: true}, } { t.Run(tt.name, func(t *testing.T) { r := newResolver(t) diff --git a/net/dns/resolver/tsdns.go b/net/dns/resolver/tsdns.go index 5a791436d..676ab15b2 100644 --- a/net/dns/resolver/tsdns.go +++ b/net/dns/resolver/tsdns.go @@ -731,7 +731,7 @@ func stubResolverForOS() (ip netip.Addr, err error) { mod: fi.ModTime(), size: fi.Size(), } - if c, ok := resolvConfCacheValue.LoadOk(); ok && c.mod == cur.mod && c.size == cur.size { + if c, ok := resolvConfCacheValue.LoadOk(); ok && c.mod.Equal(cur.mod) && c.size == cur.size { return c.ip, nil } conf, err := resolvconffile.ParseFile(resolvconffile.Path) diff --git a/net/flowtrack/flowtrack_test.go b/net/flowtrack/flowtrack_test.go index 21e2021e1..a93776905 100644 --- a/net/flowtrack/flowtrack_test.go +++ b/net/flowtrack/flowtrack_test.go @@ -75,7 +75,7 @@ func TestCache(t *testing.T) { t.Fatal("missing k3") } if *got != 30 { - t.Fatalf("got = %d; want 30", got) + t.Fatalf("got = %d; want 30", *got) } }) if err != nil { diff --git a/net/netstat/netstat_windows.go b/net/netstat/netstat_windows.go index 4b3edbdf8..e53cc56bf 100644 --- a/net/netstat/netstat_windows.go +++ b/net/netstat/netstat_windows.go @@ -269,7 +269,7 @@ func moduleInfo[entryType moduleInfoConstraint](entry *entryType, proc *windows. // GetOwnerModuleFromTcp*Entry can apparently return ERROR_SUCCESS // (NO_ERROR) on the first call without the usual first // ERROR_INSUFFICIENT_BUFFER result. Windows said success, so interpret - // that was sucessfully not having data. + // that was successfully not having data. return "", nil } basicInfo := (*_TCPIP_OWNER_MODULE_BASIC_INFO)(addr) diff --git a/tka/tka.go b/tka/tka.go index cb1c08326..df439b3f2 100644 --- a/tka/tka.go +++ b/tka/tka.go @@ -752,13 +752,9 @@ func (a *Authority) Compact(storage CompactableChonk, o CompactionOptions) error func (a *Authority) findParentForRewrite(storage Chonk, removeKeys []tkatype.KeyID, ourKey tkatype.KeyID) (AUMHash, error) { cursor := a.Head() - for { - if cursor == a.oldestAncestor.Hash() { - // We've reached as far back in our history as we can, - // so we have to rewrite from here. - break - } - + // If we reach as far back in our history as we can, we have to rewrite + // from there. + for cursor != a.oldestAncestor.Hash() { aum, err := storage.AUM(cursor) if err != nil { return AUMHash{}, fmt.Errorf("reading AUM %v: %w", cursor, err) diff --git a/tstest/integration/vms/nixos_test.go b/tstest/integration/vms/nixos_test.go index 7d7a10436..c5ea4a1e0 100644 --- a/tstest/integration/vms/nixos_test.go +++ b/tstest/integration/vms/nixos_test.go @@ -209,7 +209,7 @@ func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string { cmd.Stdout = logger.FuncWriter(t.Logf) cmd.Stderr = logger.FuncWriter(t.Logf) } else { - fname := fmt.Sprintf("nix-build-%s-%s", os.Getenv("GITHUB_RUN_NUMBER"), strings.Replace(t.Name(), "/", "-", -1)) + fname := fmt.Sprintf("nix-build-%s-%s", os.Getenv("GITHUB_RUN_NUMBER"), strings.ReplaceAll(t.Name(), "/", "-")) t.Logf("writing nix logs to %s", fname) fout, err := os.Create(fname) if err != nil { diff --git a/tsweb/vcstime/vcstime_test.go b/tsweb/vcstime/vcstime_test.go index c8664b584..60190899d 100644 --- a/tsweb/vcstime/vcstime_test.go +++ b/tsweb/vcstime/vcstime_test.go @@ -36,7 +36,7 @@ func TestNewStampsModTime(t *testing.T) { if err != nil { t.Fatal(err) } - if got := info.ModTime(); got != mod { + if got := info.ModTime(); !got.Equal(mod) { t.Errorf("file ModTime = %v, want %v", got, mod) } if got, want := info.Name(), "hello.txt"; got != want { @@ -66,7 +66,7 @@ func TestNewStampsModTime(t *testing.T) { if err != nil { t.Fatal(err) } - if got := i.ModTime(); got != mod { + if got := i.ModTime(); !got.Equal(mod) { t.Errorf("entry %q ModTime = %v, want %v", de.Name(), got, mod) } } @@ -117,7 +117,7 @@ func TestPassthroughRealTimestamps(t *testing.T) { if err != nil { t.Fatal(err) } - if got := fi.ModTime(); got != real { + if got := fi.ModTime(); !got.Equal(real) { t.Errorf("ModTime = %v, want untouched %v", got, real) } } @@ -141,7 +141,7 @@ func TestVCSTime(t *testing.T) { bi := &debug.BuildInfo{Settings: []debug.BuildSetting{ {Key: "vcs.time", Value: good.Format(time.RFC3339)}, }} - if got := vcsTime(bi); got != good { + if got := vcsTime(bi); !got.Equal(good) { t.Errorf("vcsTime = %v, want %v", got, good) } }) @@ -178,7 +178,7 @@ func TestFSMatchesModTime(t *testing.T) { if err != nil { t.Fatal(err) } - if got := fi.ModTime(); got != mod { + if got := fi.ModTime(); !got.Equal(mod) { t.Errorf("ModTime = %v, want %v", got, mod) } } @@ -194,7 +194,7 @@ func TestModTimeMatchesBuildInfo(t *testing.T) { } } } - if got := ModTime(); got != want { + if got := ModTime(); !got.Equal(want) { t.Errorf("ModTime = %v, want %v", got, want) } } @@ -209,7 +209,7 @@ func TestWrappedSubFS(t *testing.T) { if err != nil { t.Fatal(err) } - if got := fi.ModTime(); got != mod { + if got := fi.ModTime(); !got.Equal(mod) { t.Errorf("sub FS ModTime = %v, want %v", got, mod) } if got, err := fs.ReadFile(sub, "hello.txt"); err != nil || !strings.HasPrefix(string(got), "hello") { @@ -244,7 +244,7 @@ func TestFallbackWithoutReadDirFSOrReadFileFS(t *testing.T) { if err != nil { t.Fatal(err) } - if got := i.ModTime(); got != mod { + if got := i.ModTime(); !got.Equal(mod) { t.Errorf("entry %q ModTime = %v, want %v", de.Name(), got, mod) } } @@ -271,7 +271,7 @@ func TestFallbackWithoutReadDirFSOrReadFileFS(t *testing.T) { if len(des) != 1 || des[0].Name() != "b.txt" { t.Fatalf("ReadDir = %v, want [b.txt]", des) } - if i, _ := des[0].Info(); i.ModTime() != mod { + if i, _ := des[0].Info(); !i.ModTime().Equal(mod) { t.Errorf("entry b.txt ModTime = %v, want %v", i.ModTime(), mod) } } diff --git a/util/osdiag/osdiag_windows.go b/util/osdiag/osdiag_windows.go index ff489989c..7ce4d34ab 100644 --- a/util/osdiag/osdiag_windows.go +++ b/util/osdiag/osdiag_windows.go @@ -210,11 +210,11 @@ type moduleInfo struct { BaseAddress uintptr `json:"baseAddress"` Size uint32 `json:"size"` DebugInfo map[string]string `json:"debugInfo,omitempty"` // map for JSON marshaling purposes - DebugInfoErr error `json:"debugInfoErr,omitempty"` + DebugInfoErr error `json:"debugInfoErr,omitzero"` Signature map[string]string `json:"signature,omitempty"` // map for JSON marshaling purposes - SignatureErr error `json:"signatureErr,omitempty"` + SignatureErr error `json:"signatureErr,omitzero"` VersionInfo map[string]string `json:"versionInfo,omitempty"` // map for JSON marshaling purposes - VersionErr error `json:"versionErr,omitempty"` + VersionErr error `json:"versionErr,omitzero"` } func (mi *moduleInfo) setVersionInfo() { @@ -395,9 +395,9 @@ type wsaProtocolInfoOutput struct { ServiceFlags1 string `json:"serviceFlags1"` ProviderFlags string `json:"providerFlags"` Path string `json:"path,omitempty"` - PathErr error `json:"pathErr,omitempty"` + PathErr error `json:"pathErr,omitzero"` Category string `json:"category,omitempty"` - CategoryErr error `json:"categoryErr,omitempty"` + CategoryErr error `json:"categoryErr,omitzero"` BaseProviderID string `json:"baseProviderID,omitempty"` LayerProviderID string `json:"layerProviderID,omitempty"` Chain []uint32 `json:"chain,omitempty"` @@ -509,9 +509,9 @@ const ( type secProductInfo struct { Name string `json:"name,omitempty"` - NameErr error `json:"nameErr,omitempty"` + NameErr error `json:"nameErr,omitzero"` State string `json:"state,omitempty"` - StateErr error `json:"stateErr,omitempty"` + StateErr error `json:"stateErr,omitzero"` } func getSecurityInfo() map[string]any { diff --git a/util/winutil/startupinfo_windows.go b/util/winutil/startupinfo_windows.go index e96209764..7cdf26230 100644 --- a/util/winutil/startupinfo_windows.go +++ b/util/winutil/startupinfo_windows.go @@ -100,6 +100,7 @@ func (sib *StartupInfoBuilder) Resolve() (startupInfo *windows.StartupInfo, inhe switch v := val.(type) { case windows.Handle: // An individual handle is pointer-width and is thus passed by value. + //lint:ignore unsafeptr Windows handles aren't Go pointers. pval = unsafe.Pointer(v) sval = unsafe.Sizeof(v) case []uint64: diff --git a/util/winutil/svcdiag_windows.go b/util/winutil/svcdiag_windows.go index b9356d2f2..6dfdd3a28 100644 --- a/util/winutil/svcdiag_windows.go +++ b/util/winutil/svcdiag_windows.go @@ -122,8 +122,8 @@ type svcStateLogEntry struct { ServiceType string `json:"serviceType"` State string `json:"state"` StartupType string `json:"startupType"` - Triggers *_SERVICE_TRIGGER_INFO `json:"triggers,omitempty"` - TriggersError error `json:"triggersError,omitempty"` + Triggers *_SERVICE_TRIGGER_INFO `json:"triggers,omitzero"` + TriggersError error `json:"triggersError,omitzero"` } type _SERVICE_TRIGGER_SPECIFIC_DATA_ITEM struct { diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index 1d438c003..1cba49cd6 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -3723,7 +3723,7 @@ func TestMaybeRebindOnWriteError(t *testing.T) { conn.maybeRebindOnWriteError(err) newTime := conn.lastErrRebind.Load() - if newTime == lastRebindTime { + if newTime.Equal(lastRebindTime) { t.Errorf("expected a rebind to occur") } if newTime.Sub(lastRebindTime) < 5*time.Second { diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index a089e22d0..b8c634207 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -925,7 +925,7 @@ func (ns *Impl) handleLocalPackets(p *packet.Parsed, t *tstun.Wrapper, gro *gro. return filter.Accept, gro } if p.IPProto != ipproto.TCP { - // We currenly only support VIP services over TCP. If service is in Tun mode, + // We currently only support VIP services over TCP. If service is in Tun mode, // it's up to the service host to set up local packet handling which shouldn't // arrive here. return filter.DropSilently, gro diff --git a/wgengine/router/osrouter/ifconfig_windows.go b/wgengine/router/osrouter/ifconfig_windows.go index d24fe9790..23c2de9e4 100644 --- a/wgengine/router/osrouter/ifconfig_windows.go +++ b/wgengine/router/osrouter/ifconfig_windows.go @@ -456,7 +456,7 @@ func configureInterface(cfg *router.Config, tun *tun.NativeTun, ht *health.Track var errAcc error err = syncRoutes(iface, deduplicatedRoutes, cfg.LocalAddrs) - if err != nil && errAcc == nil { + if err != nil { log.Printf("setroutes: %v", err) errAcc = err } diff --git a/wgengine/router/osrouter/router_linux.go b/wgengine/router/osrouter/router_linux.go index 1e8bfa7ef..558f07351 100644 --- a/wgengine/router/osrouter/router_linux.go +++ b/wgengine/router/osrouter/router_linux.go @@ -1429,7 +1429,7 @@ func (r *linuxRouter) enableIPForwarding() { } func writeSysctl(key, val string) error { - fn := "/proc/sys/" + strings.Replace(key, ".", "/", -1) + fn := "/proc/sys/" + strings.ReplaceAll(key, ".", "/") if err := os.WriteFile(fn, []byte(val), 0644); err != nil { return fmt.Errorf("sysctl(%v=%v): %v", key, val, err) }