all: fix problems found by running vet and staticcheck everywhere

These were hidden because golangci-lint only reported problems on
changed lines and vet never ran for windows or darwin. Among them, a
tsconnect build ignored precompression errors and two printf calls
formatted pointers with %d.

Fixing them first clears the way for an upcoming rework of vet in CI
that unifies our assorted static analysis checkers into one tool.

Fixes #22652
Updates #22653

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Change-Id: I89e8f5899a2fb9a2d477379e0c2c977d48e001a0
This commit is contained in:
Brad Fitzpatrick authored and Brad Fitzpatrick committed 2026-12-02 02:45:54 -08:00
1 parent cd4f621399
commit ba01cd8c93
24 files changed
+53 -57

No files matched your search

+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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)
+3 -6
View File
@@ -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]")
+2 -3
View File
@@ -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,
},
},
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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)
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
}
}
+1 -1
View File
@@ -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
+3
View File
@@ -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
@@ -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)
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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)
+3 -7
View File
@@ -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)
+1 -1
View File
@@ -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 {
+9 -9
View File
@@ -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)
}
}
+7 -7
View File
@@ -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 {
+1
View File
@@ -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:
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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)
}