ShellCrash icon indicating copy to clipboard operation
ShellCrash copied to clipboard

[Bug] setconfig 函数会匹配到配置字段的内容,特定情况下会造成配置文件错乱

Open CwithW opened this issue 11 months ago • 1 comments

Verify steps

  • [x] 我已经在 Issue Tracker 中找过我要提出的问题 I have searched on the issue tracker for a related issue.
  • [x] 我已经使用公测版本测试过,问题依旧存在 I have tested using the test mod, and the issue still exists.
  • [x] 我已经仔细看过 常见问题 并无法自行解决问题

Description

版本:1.9.3beta8

In init.sh, setconfig函数被用来写入配置文件。

setconfig() { #脚本配置工具
    #参数1代表变量名,参数2代表变量值,参数3即文件路径
    [ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
    if grep -q "^${1}=" "$configpath"; then
        sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
    else
        printf '%s=%s\n' "$1" "$2" >>"$configpath"
    fi
}

grep匹配用了^匹配行开头,但是用来替换的sed没有用^,导致替换时可以匹配到配置文件里其他字段(尤其是订阅链接)里的内容,造成配置文件错乱。

复现: 6-2 设置订阅链接为http://example.com?sniffer=1 7-4 开启域名嗅探,然后4关闭域名嗅探 (执行了setconfig sniffer $sniffer两次)

此时,配置文件中:

Https='http://example.com/?sniffer=未启用
...                                                                                                               
sniffer=未启用

修复:将sed -i "s#${1}=.*#${1}=${2}#g" "$configpath" 改为 sed -i "s#^${1}=.*#${1}=${2}#g" "$configpath"

CwithW avatar Dec 15 '25 15:12 CwithW

感谢提醒,已修复!

juewuy avatar Dec 17 '25 13:12 juewuy