From a6abc4c150df3111841b90c7df708ca9312660d8 Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 9 Dec 2020 18:05:41 -0500 Subject: [PATCH] ssh_known_hosts_file: fix bug with empty list (fix #11) 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. --- src/ssh_options.jl | 3 ++- test/runtests.jl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ssh_options.jl b/src/ssh_options.jl index 49eb433..611d8b5 100644 --- a/src/ssh_options.jl +++ b/src/ssh_options.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5e85a2b..e14f6fd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")