lib/model: Prevent warning on request in paused folder (fixes #4870)

This commit is contained in:
Simon Frei 2018-04-09 21:55:52 +02:00 committed by Audrius Butkevicius
parent e9c6795ef8
commit 4072ae4d05

View File

@ -1309,23 +1309,33 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
return protocol.ErrInvalid return protocol.ErrInvalid
} }
if !m.folderSharedWith(folder, deviceID) { // Make sure the path is valid and in canonical form
l.Warnf("Request from %s for file %s in unshared folder %q", deviceID, name, folder) var err error
return protocol.ErrNoSuchFile if name, err = fs.Canonicalize(name); err != nil {
} l.Debugf("Request from %s in paused folder %q for invalid filename %s", deviceID, folder, name)
if deviceID != protocol.LocalDeviceID { return protocol.ErrInvalid
l.Debugf("%v REQ(in): %s: %q / %q o=%d s=%d t=%v", m, deviceID, folder, name, offset, len(buf), fromTemporary)
} }
m.fmut.RLock() m.fmut.RLock()
folderCfg := m.folderCfgs[folder] folderCfg := m.folderCfgs[folder]
folderIgnores := m.folderIgnores[folder] folderIgnores := m.folderIgnores[folder]
m.fmut.RUnlock() m.fmut.RUnlock()
folderFs := folderCfg.Filesystem() if folderCfg.Paused {
l.Debugf("Request from %s for file %s in paused folder %q", deviceID, name, folder)
return protocol.ErrInvalid
}
// Having passed the rootedJoinedPath check above, we know "name" is if !m.folderSharedWith(folder, deviceID) {
// acceptable relative to "folderPath" and in canonical form, so we can l.Warnf("Request from %s for file %s in unshared folder %q", deviceID, name, folder)
// trust it. return protocol.ErrNoSuchFile
}
if deviceID != protocol.LocalDeviceID {
l.Debugf("%v REQ(in): %s: %q / %q o=%d s=%d t=%v", m, deviceID, folder, name, offset, len(buf), fromTemporary)
}
folderFs := folderCfg.Filesystem()
if fs.IsInternal(name) { if fs.IsInternal(name) {
l.Debugf("%v REQ(in) for internal file: %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, len(buf)) l.Debugf("%v REQ(in) for internal file: %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, len(buf))
@ -1366,12 +1376,12 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
return protocol.ErrNoSuchFile return protocol.ErrNoSuchFile
} }
err := readOffsetIntoBuf(folderFs, name, offset, buf) if err = readOffsetIntoBuf(folderFs, name, offset, buf); fs.IsNotExist(err) {
if fs.IsNotExist(err) {
return protocol.ErrNoSuchFile return protocol.ErrNoSuchFile
} else if err != nil { } else if err != nil {
return protocol.ErrGeneric return protocol.ErrGeneric
} }
return nil return nil
} }
@ -1910,7 +1920,7 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
m.fmut.RUnlock() m.fmut.RUnlock()
mtimefs := fset.MtimeFS() mtimefs := fset.MtimeFS()
for i := 0; i < len(subDirs); i++ { for i := range subDirs {
sub := osutil.NativeFilename(subDirs[i]) sub := osutil.NativeFilename(subDirs[i])
if sub == "" { if sub == "" {
@ -1920,11 +1930,6 @@ func (m *Model) internalScanFolderSubdirs(ctx context.Context, folder string, su
break break
} }
// We test each path by joining with "root". What we join with is
// not relevant, we just want the dotdot escape detection here. For
// historical reasons we may get paths that end in a slash. We
// remove that first to allow the rootedJoinedPath to pass.
sub = strings.TrimRight(sub, string(fs.PathSeparator))
subDirs[i] = sub subDirs[i] = sub
} }