Browse Source

Do not crash on invalid lines

Julian Kornberger 10 years ago
parent
commit
107079411b
2 changed files with 7 additions and 4 deletions
  1. 6 4
      ftp.go
  2. 1 0
      parse_test.go

+ 6 - 4
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 {

+ 1 - 0
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) {