From 107079411b63470bb6456cb7dfb0bbc62c78889b Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Dec 2015 00:09:00 +0100 Subject: [PATCH 1/3] Do not crash on invalid lines --- ftp.go | 10 ++++++---- parse_test.go | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ftp.go b/ftp.go index 34377b2..b334c65 100644 --- a/ftp.go +++ b/ftp.go @@ -403,10 +403,12 @@ func parseDirListLine(line string) (*Entry, error) { // Try various time formats that DIR might use, and stop when one works. for _, format := range dirTimeFormats { - e.Time, err = time.Parse(format, line[:len(format)]) - if err == nil { - line = line[len(format):] - break + if len(line) > len(format) { + e.Time, err = time.Parse(format, line[:len(format)]) + if err == nil { + line = line[len(format):] + break + } } } if err != nil { diff --git a/parse_test.go b/parse_test.go index 1236605..0d373f7 100644 --- a/parse_test.go +++ b/parse_test.go @@ -58,6 +58,7 @@ var listTestsFail = []unsupportedLine{ {"drwxr-xr-x 3 110 1002 3 Dec 02 209 pub", "Invalid year format in time string"}, {"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"}, {"Zrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"}, + {"total 1", "Unsupported LIST line"}, } func TestParseValidListLine(t *testing.T) { From 1fc6b70adc396ec89c0f8971b504ea4ea3bd8175 Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Dec 2015 12:17:09 +0100 Subject: [PATCH 2/3] Another fix for the line parser --- ftp.go | 4 ++++ parse_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/ftp.go b/ftp.go index b334c65..fd3648e 100644 --- a/ftp.go +++ b/ftp.go @@ -347,6 +347,10 @@ func parseLsListLine(line string) (*Entry, error) { return e, nil } + if len(fields) < 8 { + return nil, errUnsupportedListLine + } + if fields[1] == "0" { e := &Entry{ Type: EntryTypeFile, diff --git a/parse_test.go b/parse_test.go index 0d373f7..b442800 100644 --- a/parse_test.go +++ b/parse_test.go @@ -59,6 +59,7 @@ var listTestsFail = []unsupportedLine{ {"modify=20150806235817;invalid;UNIX.owner=0; movies", "Unsupported LIST line"}, {"Zrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin", "Unknown entry type"}, {"total 1", "Unsupported LIST line"}, + {"", "Unsupported LIST line"}, } func TestParseValidListLine(t *testing.T) { From e077f903653f7a0cf7419af13625317504027c4c Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Mon, 28 Dec 2015 12:33:00 +0100 Subject: [PATCH 3/3] Fix Travis CI --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 02b38e9..6ba117e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,11 @@ go: - 1.5.1 before_install: - sudo mkdir --mode 0777 -p /var/ftp/incoming +- sudo apt-get update -qq - sudo apt-get install -qq vsftpd - sudo cp $TRAVIS_BUILD_DIR/.vsftpd.conf /etc/vsftpd.conf - sudo service vsftpd restart +- sudo sysctl net.ipv6.conf.lo.disable_ipv6=0 - go get github.com/axw/gocov/gocov - go get github.com/mattn/goveralls script: