Do not crash on invalid lines
This commit is contained in:
parent
f780314026
commit
107079411b
2
ftp.go
2
ftp.go
@ -403,12 +403,14 @@ func parseDirListLine(line string) (*Entry, error) {
|
||||
|
||||
// Try various time formats that DIR might use, and stop when one works.
|
||||
for _, format := range dirTimeFormats {
|
||||
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 {
|
||||
// None of the time formats worked.
|
||||
return nil, errUnsupportedListLine
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user