Skip to content

Commit

Permalink
ssh_known_hosts_file: fix bug with empty list (fix #11) (#13)
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 authored Dec 9, 2020
1 parent c4a2771 commit a251de1
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 @@ -118,6 +118,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

2 comments on commit a251de1

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/26148

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" a251de1e1c8ce4edc351d0f05233ba7fe7d2c27a
git push origin v1.2.0

Please sign in to comment.