From 4eb0e24c6ee017dd9eb243a84504f3a5f8dba520 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 20 Jun 2015 20:21:05 +0200 Subject: [PATCH] Sanitize rescan interval values (fixes #1978) --- internal/config/config.go | 7 +++++++ internal/config/config_test.go | 14 ++++++++++++++ internal/config/testdata/largeinterval.xml | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 internal/config/testdata/largeinterval.xml diff --git a/internal/config/config.go b/internal/config/config.go index 025754e2f..7611dedee 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -28,6 +28,7 @@ import ( const ( OldestHandledVersion = 5 CurrentVersion = 10 + MaxRescanIntervalS = 365 * 24 * 60 * 60 ) type Configuration struct { @@ -330,6 +331,12 @@ func (cfg *Configuration) prepare(myID protocol.DeviceID) { folder.ID = "default" } + if folder.RescanIntervalS > MaxRescanIntervalS { + folder.RescanIntervalS = MaxRescanIntervalS + } else if folder.RescanIntervalS < 0 { + folder.RescanIntervalS = 0 + } + if seen, ok := seenFolders[folder.ID]; ok { l.Warnf("Multiple folders with ID %q; disabling", folder.ID) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 1192ab827..b792b0eb4 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -578,3 +578,17 @@ func TestPullOrder(t *testing.T) { } } } + +func TestLargeRescanInterval(t *testing.T) { + wrapper, err := Load("testdata/largeinterval.xml", device1) + if err != nil { + t.Fatal(err) + } + + if wrapper.Folders()["l1"].RescanIntervalS != MaxRescanIntervalS { + t.Error("too large rescan interval should be maxed out") + } + if wrapper.Folders()["l2"].RescanIntervalS != 0 { + t.Error("negative rescan interval should become zero") + } +} diff --git a/internal/config/testdata/largeinterval.xml b/internal/config/testdata/largeinterval.xml new file mode 100644 index 000000000..00ec2f732 --- /dev/null +++ b/internal/config/testdata/largeinterval.xml @@ -0,0 +1,4 @@ + + + +