Skip to content

Commit 79be16d

Browse files
committed
Merge tag 'v1.52.1' into sunos-1.52
Release 1.52.1
2 parents 0338d13 + 16c59d2 commit 79be16d

File tree

4 files changed

+162
-2
lines changed

4 files changed

+162
-2
lines changed

VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.52.0
1+
1.52.1

clientupdate/clientupdate.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func (up *Updater) updateSynology() error {
279279
return nil
280280
}
281281

282+
up.cleanupOldDownloads(filepath.Join(os.TempDir(), "tailscale-update*", "*.spk"))
282283
// Download the SPK into a temporary directory.
283284
spkDir, err := os.MkdirTemp("", "tailscale-update")
284285
if err != nil {
@@ -733,6 +734,7 @@ func (up *Updater) updateWindows() error {
733734
if err := os.MkdirAll(msiDir, 0700); err != nil {
734735
return err
735736
}
737+
up.cleanupOldDownloads(filepath.Join(msiDir, "*.msi"))
736738
pkgsPath := fmt.Sprintf("%s/tailscale-setup-%s-%s.msi", up.track, ver, arch)
737739
msiTarget := filepath.Join(msiDir, path.Base(pkgsPath))
738740
if err := up.downloadURLToFile(pkgsPath, msiTarget); err != nil {
@@ -821,6 +823,30 @@ func (up *Updater) installMSI(msi string) error {
821823
return err
822824
}
823825

826+
// cleanupOldDownloads removes all files matching glob (see filepath.Glob).
827+
// Only regular files are removed, so the glob must match specific files and
828+
// not directories.
829+
func (up *Updater) cleanupOldDownloads(glob string) {
830+
matches, err := filepath.Glob(glob)
831+
if err != nil {
832+
up.Logf("cleaning up old downloads: %v", err)
833+
return
834+
}
835+
for _, m := range matches {
836+
s, err := os.Lstat(m)
837+
if err != nil {
838+
up.Logf("cleaning up old downloads: %v", err)
839+
continue
840+
}
841+
if !s.Mode().IsRegular() {
842+
continue
843+
}
844+
if err := os.Remove(m); err != nil {
845+
up.Logf("cleaning up old downloads: %v", err)
846+
}
847+
}
848+
}
849+
824850
func msiUUIDForVersion(ver string) string {
825851
arch := runtime.GOARCH
826852
if arch == "386" {

clientupdate/clientupdate_test.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"maps"
1212
"os"
1313
"path/filepath"
14+
"slices"
15+
"sort"
1416
"strings"
1517
"testing"
1618
)
@@ -683,3 +685,113 @@ func TestWriteFileSymlink(t *testing.T) {
683685
}
684686
}
685687
}
688+
689+
func TestCleanupOldDownloads(t *testing.T) {
690+
tests := []struct {
691+
desc string
692+
before []string
693+
symlinks map[string]string
694+
glob string
695+
after []string
696+
}{
697+
{
698+
desc: "MSIs",
699+
before: []string{
700+
"MSICache/tailscale-1.0.0.msi",
701+
"MSICache/tailscale-1.1.0.msi",
702+
"MSICache/readme.txt",
703+
},
704+
glob: "MSICache/*.msi",
705+
after: []string{
706+
"MSICache/readme.txt",
707+
},
708+
},
709+
{
710+
desc: "SPKs",
711+
before: []string{
712+
"tmp/tailscale-update-1/tailscale-1.0.0.spk",
713+
"tmp/tailscale-update-2/tailscale-1.1.0.spk",
714+
"tmp/readme.txt",
715+
"tmp/tailscale-update-3",
716+
"tmp/tailscale-update-4/tailscale-1.3.0",
717+
},
718+
glob: "tmp/tailscale-update*/*.spk",
719+
after: []string{
720+
"tmp/readme.txt",
721+
"tmp/tailscale-update-3",
722+
"tmp/tailscale-update-4/tailscale-1.3.0",
723+
},
724+
},
725+
{
726+
desc: "empty-target",
727+
before: []string{},
728+
glob: "tmp/tailscale-update*/*.spk",
729+
after: []string{},
730+
},
731+
{
732+
desc: "keep-dirs",
733+
before: []string{
734+
"tmp/tailscale-update-1/tailscale-1.0.0.spk",
735+
},
736+
glob: "tmp/tailscale-update*",
737+
after: []string{
738+
"tmp/tailscale-update-1/tailscale-1.0.0.spk",
739+
},
740+
},
741+
{
742+
desc: "no-follow-symlinks",
743+
before: []string{
744+
"MSICache/tailscale-1.0.0.msi",
745+
"MSICache/tailscale-1.1.0.msi",
746+
"MSICache/readme.txt",
747+
},
748+
symlinks: map[string]string{
749+
"MSICache/tailscale-1.3.0.msi": "MSICache/tailscale-1.0.0.msi",
750+
"MSICache/tailscale-1.4.0.msi": "MSICache/readme.txt",
751+
},
752+
glob: "MSICache/*.msi",
753+
after: []string{
754+
"MSICache/tailscale-1.3.0.msi",
755+
"MSICache/tailscale-1.4.0.msi",
756+
"MSICache/readme.txt",
757+
},
758+
},
759+
}
760+
for _, tt := range tests {
761+
t.Run(tt.desc, func(t *testing.T) {
762+
dir := t.TempDir()
763+
for _, p := range tt.before {
764+
if err := os.MkdirAll(filepath.Join(dir, filepath.Dir(p)), 0700); err != nil {
765+
t.Fatal(err)
766+
}
767+
if err := os.WriteFile(filepath.Join(dir, p), []byte(tt.desc), 0600); err != nil {
768+
t.Fatal(err)
769+
}
770+
}
771+
for from, to := range tt.symlinks {
772+
if err := os.Symlink(filepath.Join(dir, to), filepath.Join(dir, from)); err != nil {
773+
t.Fatal(err)
774+
}
775+
}
776+
777+
up := &Updater{Arguments: Arguments{Logf: t.Logf}}
778+
up.cleanupOldDownloads(filepath.Join(dir, tt.glob))
779+
780+
var after []string
781+
if err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
782+
if !d.IsDir() {
783+
after = append(after, strings.TrimPrefix(filepath.ToSlash(path), filepath.ToSlash(dir)+"/"))
784+
}
785+
return nil
786+
}); err != nil {
787+
t.Fatal(err)
788+
}
789+
790+
sort.Strings(after)
791+
sort.Strings(tt.after)
792+
if !slices.Equal(after, tt.after) {
793+
t.Errorf("got files after cleanup: %q, want: %q", after, tt.after)
794+
}
795+
})
796+
}
797+
}

cmd/tailscaled/tailscaled_windows.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"os"
3131
"os/exec"
3232
"os/signal"
33+
"path/filepath"
3334
"sync"
3435
"syscall"
3536
"time"
@@ -299,6 +300,14 @@ func beWindowsSubprocess() bool {
299300
}
300301
}()
301302

303+
// Pre-load wintun.dll using a fully-qualified path so that wintun-go
304+
// loads our copy and not some (possibly outdated) copy dropped in system32.
305+
// (OSS Issue #10023)
306+
fqWintunPath := fullyQualifiedWintunPath(log.Printf)
307+
if _, err := windows.LoadDLL(fqWintunPath); err != nil {
308+
log.Printf("Error pre-loading \"%s\": %v", fqWintunPath, err)
309+
}
310+
302311
sys := new(tsd.System)
303312
netMon, err := netmon.New(log.Printf)
304313
if err != nil {
@@ -507,7 +516,7 @@ func babysitProc(ctx context.Context, args []string, logf logger.Logf) {
507516
}
508517

509518
func uninstallWinTun(logf logger.Logf) {
510-
dll := windows.NewLazyDLL("wintun.dll")
519+
dll := windows.NewLazyDLL(fullyQualifiedWintunPath(logf))
511520
if err := dll.Load(); err != nil {
512521
logf("Cannot load wintun.dll for uninstall: %v", err)
513522
return
@@ -517,3 +526,16 @@ func uninstallWinTun(logf logger.Logf) {
517526
err := wintun.Uninstall()
518527
logf("Uninstall: %v", err)
519528
}
529+
530+
func fullyQualifiedWintunPath(logf logger.Logf) string {
531+
var dir string
532+
var buf [windows.MAX_PATH]uint16
533+
length := uint32(len(buf))
534+
if err := windows.QueryFullProcessImageName(windows.CurrentProcess(), 0, &buf[0], &length); err != nil {
535+
logf("QueryFullProcessImageName failed: %v", err)
536+
} else {
537+
dir = filepath.Dir(windows.UTF16ToString(buf[:length]))
538+
}
539+
540+
return filepath.Join(dir, "wintun.dll")
541+
}

0 commit comments

Comments
 (0)