Fix potential index out of range error

I had some extra spaces and junk in my ssh config and it was causing
this part of the code to fail with an out of range error.
This commit is contained in:
Sergey Lukjanov
2018-01-27 00:28:50 -08:00
committed by Kevin Burke
parent 802051befe
commit c665f6f442
3 changed files with 21 additions and 5 deletions

View File

@@ -107,19 +107,17 @@ func (p *sshParser) parseKV() sshParserStateFn {
}
if strings.ToLower(key.val) == "host" {
strPatterns := strings.Split(val.val, " ")
patterns := make([]*Pattern, 0)
for i := range strPatterns {
if strPatterns[i] == "" {
strPatterns = append(strPatterns[:i], strPatterns[i+1:]...)
continue
}
}
patterns := make([]*Pattern, len(strPatterns))
for i := range strPatterns {
pat, err := NewPattern(strPatterns[i])
if err != nil {
p.raiseErrorf(val, "Invalid host pattern: %v", err)
return nil
}
patterns[i] = pat
patterns = append(patterns, pat)
}
p.config.Hosts = append(p.config.Hosts, &Host{
Patterns: patterns,