From 7d3648dc46f91bf444c5875f03cadae51cff8aa9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 12 Nov 2021 12:48:14 +0000 Subject: [PATCH] serve ftp: check --passive-port arguments are correct See: https://forum.rclone.org/t/serve-ftp-passive-port-validity-check/27458 --- cmd/serve/ftp/ftp.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/serve/ftp/ftp.go b/cmd/serve/ftp/ftp.go index a2a4df159..b8022599e 100644 --- a/cmd/serve/ftp/ftp.go +++ b/cmd/serve/ftp/ftp.go @@ -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",