soulteary / ssh-config

1MB size, 100% Coverage, Use more expressive YAML / JSON to manage your Config files. --- 1MB大小,100% 测试覆盖,使用更具表现力的YAML / JSON来管理您的配置文件。
https://soulteary.com/2024/10/15/manage-ssh-configuration-using-structure-data-ssh-config-tool.html
Apache License 2.0
42 stars 4 forks source link

Potential Panic in `GroupSSHConfigFromString` Due to Nil Map Assignment #1

Open eli-yip opened 5 days ago

eli-yip commented 5 days ago

In the GroupSSHConfigFromString function, the line hostConfigs[currentHost].Config[key] = value does not check whether the hostConfigs[currentHost].Config map is nil.

While logically, a host's config should always appear after the host is declared, meaning the map is typically not nil, there's an edge case where the map remains uninitialized. This happens if the input only contains a single non-comment line, such as:

Include ~/.ssh/config.d/*

In this case, the Config map is not initialized, leading to the following error: panic: assignment to entry in nil map.

A check should be added to ensure the map is initialized before assignment.


Additionally, I believe the current directory reading mechanism could introduce several potential bugs, such as reading files like known_hosts which should not be processed. I think only configuration files should be read.

Of course, if you believe I should only operate on directories that exclusively contain configuration files, such as config.d, then the issue mentioned above would not arise. However, I still believe that since the design goal of this program is to simplify ssh configuration files, it should recursively start from the .ssh/config file, read all configurations, and process them accordingly.

soulteary commented 6 hours ago

Thanks for the feedback and suggestions.

The code submission automatically closed the issue, I reopened it, and when feat:config-scan is completed, the issue will be closed