lib/osutil: Replace IsDir with TraversesSymlink (fixes #3839)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3883
LGTM: calmh
This commit is contained in:
Audrius Butkevicius
2017-01-10 07:09:31 +00:00
committed by Jakob Borg
parent 8d2a31e38e
commit 1a1e35d998
5 changed files with 98 additions and 70 deletions

View File

@@ -121,7 +121,6 @@ var (
errDevicePaused = errors.New("device is paused")
errDeviceIgnored = errors.New("device is ignored")
errNotRelative = errors.New("not a relative path")
errNotDir = errors.New("parent is not a directory")
)
// NewModel creates and starts a new model. The model starts in read-only mode,
@@ -1159,8 +1158,8 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
return protocol.ErrNoSuchFile
}
if !osutil.IsDir(folderPath, filepath.Dir(name)) {
l.Debugf("%v REQ(in) for file not in dir: %s: %q / %q o=%d s=%d", m, deviceID, folder, name, offset, len(buf))
if err := osutil.TraversesSymlink(folderPath, filepath.Dir(name)); err != nil {
l.Debugf("%v REQ(in) traversal check: %s - %s: %q / %q o=%d s=%d", m, err, deviceID, folder, name, offset, len(buf))
return protocol.ErrNoSuchFile
}

View File

@@ -431,8 +431,8 @@ func (f *sendReceiveFolder) pullerIteration(ignores *ignore.Matcher) int {
for _, fi := range processDirectly {
// Verify that the thing we are handling lives inside a directory,
// and not a symlink or empty space.
if !osutil.IsDir(f.dir, filepath.Dir(fi.Name)) {
f.newError(fi.Name, errNotDir)
if err := osutil.TraversesSymlink(f.dir, filepath.Dir(fi.Name)); err != nil {
f.newError(fi.Name, err)
continue
}
@@ -520,8 +520,8 @@ nextFile:
// Verify that the thing we are handling lives inside a directory,
// and not a symlink or empty space.
if !osutil.IsDir(f.dir, filepath.Dir(fi.Name)) {
f.newError(fi.Name, errNotDir)
if err := osutil.TraversesSymlink(f.dir, filepath.Dir(fi.Name)); err != nil {
f.newError(fi.Name, err)
continue
}