Skip to content

Commit

Permalink
Prevent get_hostname() from crashing.
Browse files Browse the repository at this point in the history
get_hostname() crashes if "Match" is not followed by a
"Host" section in .ssh/config.

Closes paramiko#2339
  • Loading branch information
dirtyhillbilly committed Dec 28, 2023
1 parent 43980e7 commit da9f7b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion paramiko/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ def get_hostnames(self):
"""
hosts = set()
for entry in self._config:
hosts.update(entry["host"])
if "host" in entry:
hosts.update(entry["host"])
return hosts

def _pattern_matches(self, patterns, target):
Expand Down
1 change: 1 addition & 0 deletions tests/configs/match-all
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Match all
User awesome

5 changes: 5 additions & 0 deletions tests/configs/match-include
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Host Foo
User bar

Match all
Include ~/.ssh/config.extra
4 changes: 4 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ def test_after_canonical_not_loaded_when_non_canonicalized(self, socket):
result = load_config("match-canonical-no").lookup("a-host")
assert "user" not in result

def test_match_include(self):
result = load_config("match-include").get_hostnames()
assert "Foo" in result


def _expect(success_on):
"""
Expand Down

0 comments on commit da9f7b6

Please sign in to comment.