Browse Source

Merge pull request #1321 from AudriusButkevicius/bitcheck

Refuse files with unknown bits set (fixes #1276)
Jakob Borg 10 years ago
parent
commit
6bbd74adcd

+ 1 - 1
Godeps/Godeps.json

@@ -31,7 +31,7 @@
 		},
 		{
 			"ImportPath": "github.com/syncthing/protocol",
-			"Rev": "442e93d3fc7728d7560c8d039a4199a77879b9f6"
+			"Rev": "4395711d26c61e7e422a8c8da43dda164f1820f4"
 		},
 		{
 			"ImportPath": "github.com/syndtr/goleveldb/leveldb",

+ 2 - 0
Godeps/_workspace/src/github.com/syncthing/protocol/protocol.go

@@ -43,6 +43,8 @@ const (
 	FlagSymlink                     = 1 << 16
 	FlagSymlinkMissingTarget        = 1 << 17
 
+	FlagsAll = (1 << iota) - 1
+
 	SymlinkTypeMask = FlagDirectory | FlagSymlinkMissingTarget
 )
 

+ 14 - 2
internal/model/model.go

@@ -485,7 +485,13 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
 
 	for i := 0; i < len(fs); {
 		lamport.Default.Tick(fs[i].Version)
-		if symlinkInvalid(fs[i].IsSymlink()) {
+		if fs[i].Flags&^protocol.FlagsAll != 0 {
+			if debug {
+				l.Debugln("dropping update for file with unknown bits set", fs[i])
+			}
+			fs[i] = fs[len(fs)-1]
+			fs = fs[:len(fs)-1]
+		} else if symlinkInvalid(fs[i].IsSymlink()) {
 			if debug {
 				l.Debugln("dropping update for unsupported symlink", fs[i])
 			}
@@ -528,7 +534,13 @@ func (m *Model) IndexUpdate(deviceID protocol.DeviceID, folder string, fs []prot
 
 	for i := 0; i < len(fs); {
 		lamport.Default.Tick(fs[i].Version)
-		if symlinkInvalid(fs[i].IsSymlink()) {
+		if fs[i].Flags&^protocol.FlagsAll != 0 {
+			if debug {
+				l.Debugln("dropping update for file with unknown bits set", fs[i])
+			}
+			fs[i] = fs[len(fs)-1]
+			fs = fs[:len(fs)-1]
+		} else if symlinkInvalid(fs[i].IsSymlink()) {
 			if debug {
 				l.Debugln("dropping update for unsupported symlink", fs[i])
 			}

+ 55 - 0
internal/model/model_test.go

@@ -525,3 +525,58 @@ func TestIgnores(t *testing.T) {
 		t.Errorf("Expected no ignores, got: %v", ignores)
 	}
 }
+
+func TestRefuseUnknownBits(t *testing.T) {
+	fcfg := config.FolderConfiguration{
+		ID:   "default",
+		Path: "testdata",
+		Devices: []config.FolderDeviceConfiguration{
+			{
+				DeviceID: device1,
+			},
+		},
+	}
+	cfg := config.Configuration{
+		Folders: []config.FolderConfiguration{fcfg},
+		Devices: []config.DeviceConfiguration{
+			{
+				DeviceID: device1,
+			},
+		},
+	}
+
+	db, _ := leveldb.Open(storage.NewMemStorage(), nil)
+	m := NewModel(config.Wrap("/tmp/test", cfg), "device", "syncthing", "dev", db)
+	m.AddFolder(fcfg)
+
+	m.ScanFolder("default")
+	m.Index(device1, "default", []protocol.FileInfo{
+		{
+			Name:  "invalid1",
+			Flags: protocol.FlagsAll + 1,
+		},
+		{
+			Name:  "invalid2",
+			Flags: protocol.FlagsAll + 2,
+		},
+		{
+			Name:  "invalid3",
+			Flags: 1 << 31,
+		},
+		{
+			Name:  "valid",
+			Flags: protocol.FlagsAll,
+		},
+	})
+
+	for _, name := range []string{"invalid1", "invalid2", "invalid3"} {
+		f, ok := m.CurrentGlobalFile("default", name)
+		if ok || f.Name == name {
+			t.Error("Invalid file found or name match")
+		}
+	}
+	f, ok := m.CurrentGlobalFile("default", "valid")
+	if !ok || f.Name != "valid" {
+		t.Error("Valid file not found or name mismatch", ok, f)
+	}
+}