From 454bbe397d43e2f8d59c986cd341b9efb7ef0954 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 12 Sep 2022 20:09:58 +0900 Subject: [PATCH 1/2] test(_known_hosts_real): test `Include directory` in ssh_config --- test/fixtures/_known_hosts_real/config_include | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/fixtures/_known_hosts_real/config_include b/test/fixtures/_known_hosts_real/config_include index a1ae76331b4..d54f3ee56bf 100644 --- a/test/fixtures/_known_hosts_real/config_include +++ b/test/fixtures/_known_hosts_real/config_include @@ -5,3 +5,5 @@ Include ~/config_full_path Include config_relative_path # Include with wildcards, and more than one on same row Include config_asterisk* config_?uestion_mark +# Include a directory name. This is a misconfiguration, but ssh ignores it without errors. +Include ../../_known_hosts_real From 657bd08b00a9c999d11e5bdd5df6243bae2a61eb Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 12 Sep 2022 18:52:38 +0900 Subject: [PATCH 2/2] fix(_known_hosts_real): exclude directories from the config files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ville Skyttä --- bash_completion | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bash_completion b/bash_completion index ba3b85ae668..c49036244a9 100644 --- a/bash_completion +++ b/bash_completion @@ -1905,7 +1905,7 @@ _included_ssh_config_files() _comp_expand_glob files '$i' if ((${#files[@]})); then for f in "${files[@]}"; do - if [[ -r $f ]]; then + if [[ -r $f && ! -d $f ]]; then config+=("$f") # The Included file is processed to look for Included files in itself _included_ssh_config_files $f @@ -1973,10 +1973,10 @@ _known_hosts_real() # ssh config files if [[ -v configfile ]]; then - [[ -r $configfile ]] && config+=("$configfile") + [[ -r $configfile && ! -d $configfile ]] && config+=("$configfile") else for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config; do - [[ -r $i ]] && config+=("$i") + [[ -r $i && ! -d $i ]] && config+=("$i") done fi @@ -2023,7 +2023,7 @@ _known_hosts_real() for i in /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2 \ /etc/known_hosts /etc/known_hosts2 ~/.ssh/known_hosts \ ~/.ssh/known_hosts2; do - [[ -r $i ]] && kh+=("$i") + [[ -r $i && ! -d $i ]] && kh+=("$i") done for i in /etc/ssh2/knownhosts ~/.ssh2/hostkeys; do [[ -d $i ]] && khd+=("$i"/*pub)