serve ftp: check --passive-port arguments are correct

See: https://forum.rclone.org/t/serve-ftp-passive-port-validity-check/27458
This commit is contained in:
Nick Craig-Wood
2022-06-16 22:13:50 +01:00
parent a6ca4b3817
commit 7d3648dc46
+8
View File
@@ -13,6 +13,7 @@ import (
"net"
"os"
"os/user"
"regexp"
"strconv"
"sync"
"time"
@@ -128,6 +129,8 @@ type server struct {
useTLS bool
}
var passivePortsRe = regexp.MustCompile(`^\s*\d+\s*-\s*\d+\s*$`)
// Make a new FTP to serve the remote
func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
host, port, err := net.SplitHostPort(opt.ListenAddr)
@@ -151,6 +154,11 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options) (*server, error) {
}
s.useTLS = s.opt.TLSKey != ""
// Check PassivePorts format since the the server library doesn't!
if !passivePortsRe.MatchString(opt.PassivePorts) {
return nil, fmt.Errorf("invalid format for passive ports %q", opt.PassivePorts)
}
ftpopt := &ftp.ServerOpts{
Name: "Rclone FTP Server",
WelcomeMessage: "Welcome to Rclone " + fs.Version + " FTP Server",