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 26, 2023
1 parent 43980e7 commit 50d9b93
Show file tree
Hide file tree
Showing 4 changed files with 8 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

2 changes: 2 additions & 0 deletions tests/configs/match-include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Match all
Include ~/.ssh/config.extra
3 changes: 3 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,9 @@ 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):
load_config("match-include")


def _expect(success_on):
"""
Expand Down

0 comments on commit 50d9b93

Please sign in to comment.