Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore comments in ssh_config Include parsing #1199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

remil1000
Copy link

When parsing Include directive in ssh_config 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 

Copy link
Owner

@scop scop left a comment

Choose a reason for hiding this comment

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

Thanks!

In addition to the requested test suite update, please search for "conventional commits" in CONTRIBUTING.md for info how to format the commit message and modify it accordingly (+ force-push with it).

bash_completion Show resolved Hide resolved
@remil1000 remil1000 force-pushed the main branch 2 times, most recently from 57561fb to 663255d Compare June 4, 2024 06:34
Copy link
Collaborator

@akinomyoga akinomyoga left a comment

Choose a reason for hiding this comment

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

Thanks for updating.

test/t/unit/test_unit_known_hosts.py Outdated Show resolved Hide resolved
test/t/unit/test_unit_known_hosts.py Outdated Show resolved Hide resolved
bash_completion Outdated Show resolved Hide resolved
@akinomyoga
Copy link
Collaborator

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.

@akinomyoga
Copy link
Collaborator

I rebased it.

@akinomyoga
Copy link
Collaborator

I squashed commits.

A similar change for the Host directive discussed in the following places haven't been processed, but I think they can be processed in a separate PR:

#1199 (comment) by @remil1000

[...] also I realized we may be in murky waters at this inline/trailing comment support has only been gradually added to sshd_config then ssh_config around SSH version 8.5 (sshd_config - https://bugzilla.mindrot.org/attachment.cgi?id=3460 and ssh_config https://bugzilla.mindrot.org/show_bug.cgi?id=2320)

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

#1199 (comment) by @remil1000

[...] if the included file would contain Host with_comment # to be ignored then this patch would also require to update the Host directive parsing sed expression (which I already tried) only to find out it breaks https://github.com/scop/bash-completion/blob/main/test/fixtures/_known_hosts/config#L9 Host = hus%%eth0 !negated #not-a-comment as until now fixtures considered inline comments as actual content to be parsed

This is precisely why I only patched the Include parsing expression and mentioned this future Host issue, because tests would fail one after the other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants