mirror of
https://github.com/wavetermdev/ssh_config.git
synced 2026-08-05 13:43:40 -07:00
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:
@@ -324,3 +324,17 @@ func TestMatchUnsupported(t *testing.T) {
|
||||
t.Errorf("wrong error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexInRange(t *testing.T) {
|
||||
us := &UserSettings{
|
||||
userConfigFinder: testConfigFinder("testdata/config4"),
|
||||
}
|
||||
|
||||
user, err := us.GetStrict("wap", "User")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if user != "root" {
|
||||
t.Errorf("expected User to be %q, got %q", "root", user)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
# Extra space at end of line is important.
|
||||
Host wap
|
||||
User root
|
||||
KexAlgorithms diffie-hellman-group1-sha1
|
||||
Reference in New Issue
Block a user