scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.9k stars 380 forks source link

Ignore comments in ssh_config Include parsing #1199

Open remil1000 opened 4 months ago

remil1000 commented 4 months ago

When parsing Include directive in _sshconfig files, comments on the same line as the directive are considered as files to be recursively processed. Best case the recursive max_depth=16 terminates this early, but on old versions it may lead to random reads or an infinite recursion, hanging the shell process

Example before/after:

A minimal ssh client config file

$ cat config 
Include foo bar .ssh/baz # do not include

The current sed expression

$ sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\(.*\)$/\1/p' config 
foo bar .ssh/baz # do not include

Proposed change to sed expression (ignore anything coming after a #)

$ sed -ne 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\([^#]*\).*$/\1/p' config
foo bar .ssh/baz 
akinomyoga commented 4 months ago

So for example code

_comp_split hosts "$(command sed -ne 's/^[[:blank:]]*[Hh][Oo][Ss][Tt][[:blank:]=]\{1,\}\(.*\)$/\1/p' "${config[@]}")"; then

in block https://github.com/scop/bash-completion/blob/main/bash_completion#L2646-L2652 may need changes also to handle those inline comments

I agree. We want to apply the changes consistently for similar cases.