From 7fd4b0076895907664de134e3cf02c20f818caed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 9 Mar 2023 23:02:34 +0200 Subject: [PATCH] Make known_hosts hostname matching more lenient Documentation for the known_hosts file format specifies "Hostnames is a comma-separated list of patterns [...]". The regexps we had is unnecessarily strict, allowing only a subset of valid sequences. Make it more lenient (and simple) to match more valid ones. --- ssh-config-mode.el | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/ssh-config-mode.el b/ssh-config-mode.el index 5eb2500..215351e 100644 --- a/ssh-config-mode.el +++ b/ssh-config-mode.el @@ -301,6 +301,17 @@ We permit underscores.") ssh-known-hosts-regex-hostname "\\)")) +(defvar ssh-known-hosts-regex-hostname-pattern + (concat + "\\(?:" + ssh-known-hosts-regex-hostname + "\\|" + ssh-known-hosts-regex-ip + "\\|" + ;; [host-or-ip]:222 + "\\(?:\\[" ssh-known-hosts-regex-host "\\]:" ssh-known-hosts-regex-port "\\)" + "\\)")) + ;; NOTE: font-lock-studio might be of help when making changes. (defvar ssh-known-hosts-font-lock-keywords ;; We want to match lines like the following: @@ -320,27 +331,11 @@ We permit underscores.") ssh-known-hosts-regex-hashed "\\|" - ;; hostname-only - ssh-known-hosts-regex-hostname - "\\|" - - ;; ip-only - ssh-known-hosts-regex-ip - "\\|" - - ;; hostname "," ip - "\\(?:" ssh-known-hosts-regex-hostname "," ssh-known-hosts-regex-ip "\\)" - "\\|" - - ;; [host-or-ip]:222 - "\\(?:\\[" ssh-known-hosts-regex-host "\\]:" ssh-known-hosts-regex-port "\\)" - "\\|" - - ;; We arent matching ports, but they should be the same. - ;; [ssh.github.com]:443,[192.1.2.3]:443 - "\\(?:" - "\\[" ssh-known-hosts-regex-hostname "\\]:" ssh-known-hosts-regex-port "," - "\\[" ssh-known-hosts-regex-ip "\\]:" ssh-known-hosts-regex-port "\\)" + ;; list of comma separated hostname patterns + ssh-known-hosts-regex-hostname-pattern + "\\(?:," + ssh-known-hosts-regex-hostname-pattern + "\\)*" "\\)" "[ \t]+"