MCPcopy
hub / github.com/syncthing/syncthing / checkFilename

Function checkFilename

lib/protocol/protocol.go:646–670  ·  view source on GitHub ↗

checkFilename verifies that the given filename is valid according to the spec on what's allowed over the wire. A filename failing this test is grounds for disconnecting the device.

(name string)

Source from the content-addressed store, hash-verified

644// spec on what's allowed over the wire. A filename failing this test is
645// grounds for disconnecting the device.
646func checkFilename(name string) error {
647 cleanedName := path.Clean(name)
648 if cleanedName != name {
649 // The filename on the wire should be in canonical format. If
650 // Clean() managed to clean it up, there was something wrong with
651 // it.
652 return errUncleanFilename
653 }
654
655 switch name {
656 case "", ".", "..":
657 // These names are always invalid.
658 return errInvalidFilename
659 }
660 if strings.HasPrefix(name, "/") {
661 // Names are folder relative, not absolute.
662 return errInvalidFilename
663 }
664 if strings.HasPrefix(name, "../") {
665 // Starting with a dotdot is not allowed. Any other dotdots would
666 // have been handled by the Clean() call at the top.
667 return errInvalidFilename
668 }
669 return nil
670}
671
672func (c *rawConnection) handleRequest(req *Request) {
673 res, err := c.model.Request(req)

Callers 3

TestCheckFilenameFunction · 0.85
dispatcherLoopMethod · 0.85
checkFileInfoConsistencyFunction · 0.85

Calls 1

CleanMethod · 0.65

Tested by 1

TestCheckFilenameFunction · 0.68