Merge pull request #44 from digineo/fix_time_parsing
Do not crash on invalid lines
This commit is contained in:
commit
8b4b15b841
@ -3,9 +3,11 @@ go:
|
|||||||
- 1.5.1
|
- 1.5.1
|
||||||
before_install:
|
before_install:
|
||||||
- sudo mkdir --mode 0777 -p /var/ftp/incoming
|
- sudo mkdir --mode 0777 -p /var/ftp/incoming
|
||||||
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -qq vsftpd
|
- sudo apt-get install -qq vsftpd
|
||||||
- sudo cp $TRAVIS_BUILD_DIR/.vsftpd.conf /etc/vsftpd.conf
|
- sudo cp $TRAVIS_BUILD_DIR/.vsftpd.conf /etc/vsftpd.conf
|
||||||
- sudo service vsftpd restart
|
- sudo service vsftpd restart
|
||||||
|
- sudo sysctl net.ipv6.conf.lo.disable_ipv6=0
|
||||||
- go get github.com/axw/gocov/gocov
|
- go get github.com/axw/gocov/gocov
|
||||||
- go get github.com/mattn/goveralls
|
- go get github.com/mattn/goveralls
|
||||||
script:
|
script:
|
||||||
|
14
ftp.go
14
ftp.go
@ -347,6 +347,10 @@ func parseLsListLine(line string) (*Entry, error) {
|
|||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(fields) < 8 {
|
||||||
|
return nil, errUnsupportedListLine
|
||||||
|
}
|
||||||
|
|
||||||
if fields[1] == "0" {
|
if fields[1] == "0" {
|
||||||
e := &Entry{
|
e := &Entry{
|
||||||
Type: EntryTypeFile,
|
Type: EntryTypeFile,
|
||||||
@ -403,10 +407,12 @@ func parseDirListLine(line string) (*Entry, error) {
|
|||||||
|
|
||||||
// Try various time formats that DIR might use, and stop when one works.
|
// Try various time formats that DIR might use, and stop when one works.
|
||||||
for _, format := range dirTimeFormats {
|
for _, format := range dirTimeFormats {
|
||||||
e.Time, err = time.Parse(format, line[:len(format)])
|
if len(line) > len(format) {
|
||||||
if err == nil {
|
e.Time, err = time.Parse(format, line[:len(format)])
|
||||||
line = line[len(format):]
|
if err == nil {
|
||||||
break
|
line = line[len(format):]
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,6 +58,8 @@ var listTestsFail = []unsupportedLine{
|
|||||||
{"drwxr-xr-x 3 110 1002 3 Dec 02 209 pub", "Invalid year format in time string"},
|
{"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"},
|
{"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"},
|
{"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) {
|
func TestParseValidListLine(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user