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: | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								ftp.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								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,12 +407,14 @@ 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 { | ||||||
|  | 		if len(line) > len(format) { | ||||||
| 			e.Time, err = time.Parse(format, line[:len(format)]) | 			e.Time, err = time.Parse(format, line[:len(format)]) | ||||||
| 			if err == nil { | 			if err == nil { | ||||||
| 				line = line[len(format):] | 				line = line[len(format):] | ||||||
| 				break | 				break | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		// None of the time formats worked. | 		// None of the time formats worked. | ||||||
| 		return nil, errUnsupportedListLine | 		return nil, errUnsupportedListLine | ||||||
|  | |||||||
| @ -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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user