From b8e5af955bddf873c808110aa66bf93a93dcd1f4 Mon Sep 17 00:00:00 2001 From: Ludovic Fauvet Date: Sun, 7 Feb 2016 22:57:06 +0100 Subject: [PATCH] Fix a crash with pasv invalid responses --- ftp.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ftp.go b/ftp.go index fd3648e..cae2f61 100644 --- a/ftp.go +++ b/ftp.go @@ -191,12 +191,16 @@ func (c *ServerConn) pasv() (port int, err error) { start := strings.Index(line, "(") end := strings.LastIndex(line, ")") if start == -1 || end == -1 { - err = errors.New("Invalid PASV response format") - return + return 0, errors.New("Invalid PASV response format") } // We have to split the response string pasvData := strings.Split(line[start+1:end], ",") + + if len(pasvData) < 6 { + return 0, errors.New("Invalid PASV response format") + } + // Let's compute the port number portPart1, err1 := strconv.Atoi(pasvData[4]) if err1 != nil {