Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible runtime error #98

Merged
merged 1 commit into from Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions parse.go
Expand Up @@ -192,14 +192,14 @@ func parseHostedFTPLine(line string) (*Entry, error) {
}

scanner := newScanner(line)
fields := scanner.NextFields(9)
if fields[1] == "0" { // Set link count to 1 and attempt to parse as Unix.
fields[1] = "1"
newLine := strings.Join(fields, " ")
return parseLsListLine(newLine)
fields := scanner.NextFields(2)

if len(fields) < 2 || fields[1] != "0" {
return nil, errUnsupportedListLine
}
return nil, errUnsupportedListLine

// Set link count to 1 and attempt to parse as Unix.
return parseLsListLine(fields[0] + " 1 " + scanner.Remaining())
}

// parseListLine parses the various non-standard format returned by the LIST
Expand Down
1 change: 1 addition & 0 deletions parse_test.go
Expand Up @@ -69,6 +69,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"},
{"000000000x ", "Unsupported LIST line"}, // see https://github.com/jlaffaye/ftp/issues/97
{"", "Unsupported LIST line"},
}

Expand Down