Skip to content

Commit a251de1

Browse files
ssh_known_hosts_file: fix bug with empty list (fix #11) (#13)
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.
1 parent c4a2771 commit a251de1

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/ssh_options.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ function ssh_known_hosts_file()
138138
for file in files
139139
ispath(file) && return file
140140
end
141-
return files[1]
141+
return !isempty(files) ? files[1] :
142+
isfile("/dev/null") ? "/dev/null" : tempname()
142143
end
143144

144145
## helper functions

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ end
118118
# empty
119119
ENV["SSH_KNOWN_HOSTS_FILES"] = ""
120120
@test ssh_known_hosts_files() == []
121+
file = ssh_known_hosts_file()
122+
@test !isfile(file) || isempty(read(file))
121123
# explicit default
122124
ENV["SSH_KNOWN_HOSTS_FILES"] = path_sep
123125
default = joinpath(homedir(), ".ssh", "known_hosts")

0 commit comments

Comments
 (0)