Merge pull request #1321 from AudriusButkevicius/bitcheck

Refuse files with unknown bits set (fixes #1276)
This commit is contained in:
Jakob Borg 2015-02-10 20:27:14 +01:00
commit 6bbd74adcd
4 changed files with 72 additions and 3 deletions

2
Godeps/Godeps.json generated
View File

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

View File

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

View File

@ -485,7 +485,13 @@ func (m *Model) Index(deviceID protocol.DeviceID, folder string, fs []protocol.F
for i := 0; i < len(fs); { for i := 0; i < len(fs); {
lamport.Default.Tick(fs[i].Version) 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 { if debug {
l.Debugln("dropping update for unsupported symlink", fs[i]) 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); { for i := 0; i < len(fs); {
lamport.Default.Tick(fs[i].Version) 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 { if debug {
l.Debugln("dropping update for unsupported symlink", fs[i]) l.Debugln("dropping update for unsupported symlink", fs[i])
} }

View File

@ -525,3 +525,58 @@ func TestIgnores(t *testing.T) {
t.Errorf("Expected no ignores, got: %v", ignores) 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)
}
}