Skip to content

Commit

Permalink
ssh_known_hosts_file: fix bug with empty list (fix #11)
Browse files Browse the repository at this point in the history
We should return an empty file if there are no known hosts files
as this will cause no hosts to be considered known, which means
we're defaulting secure here.
  • Loading branch information
StefanKarpinski committed Dec 9, 2020
1 parent af6efad commit a6abc4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ssh_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ function ssh_known_hosts_file()
for file in files
ispath(file) && return file
end
return files[1]
return !isempty(files) ? files[1] :
isfile("/dev/null") ? "/dev/null" : tempname()
end

## helper functions
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ end
# empty
ENV["SSH_KNOWN_HOSTS_FILES"] = ""
@test ssh_known_hosts_files() == []
file = ssh_known_hosts_file()
@test !isfile(file) || isempty(read(file))
# explicit default
ENV["SSH_KNOWN_HOSTS_FILES"] = path_sep
default = joinpath(homedir(), ".ssh", "known_hosts")
Expand Down

0 comments on commit a6abc4c

Please sign in to comment.