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)
| 644 | // spec on what's allowed over the wire. A filename failing this test is |
| 645 | // grounds for disconnecting the device. |
| 646 | func 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 | |
| 672 | func (c *rawConnection) handleRequest(req *Request) { |
| 673 | res, err := c.model.Request(req) |