Skip to content

fix(install): place_config_template backup 变量 bash 3.2 安全 - #451

Merged
bigbrother666sh merged 1 commit into
TeamWiseFlow:masterfrom
bigbrother666sh:fix/install-backup-unbound-bash32
Jul 21, 2026
Merged

fix(install): place_config_template backup 变量 bash 3.2 安全#451
bigbrother666sh merged 1 commit into
TeamWiseFlow:masterfrom
bigbrother666sh:fix/install-backup-unbound-bash32

Conversation

@bigbrother666sh

Copy link
Copy Markdown
Member

macOS 自带 bash 3.2 在 set -eu 下对 local var=$(cmd) 有已知坑,升级模式跑到 [9/10] Checking config health 时报 backup?: unbound variable (line 1169 cp "$config_path" "$backup").

修法

  • backup 在函数顶部预绑定为空串 (local need_place=0 reason="" backup=""),永不 unbound
  • 后缀改用 $$.\${RANDOM:-0}(始终有值、无命令替换),弃用 $(date +%s 2>/dev/null || echo 0)
  • 消除 local-带-命令替换 模式,bash 3.2/5 通用

验证

本地 repro(真实 install.sh + set -euo pipefail + 极简 config):检测不健康 → 备份到 .bak.<pid>.<random> → 放 template → exit 0,无 unbound。

macOS 自带 bash 3.2 在 set -eu 下对 `local var=$(cmd)` 有已知坑,
升级模式跑到 'Checking config health' 时报 `backup?: unbound variable`
(line 1169 cp $backup).

修法:
- backup 在函数顶部预绑定为空串 (local need_place=0 reason="" backup=""),
  永不 unbound
- 后缀改用 $$.${RANDOM:-0} (始终有值、无命令替换), 弃用 $(date +%s ...)
- 消除 local-带-命令替换 模式, bash 3.2/5 通用
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


codes-factory-of-bg seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@bigbrother666sh
bigbrother666sh merged commit 2658e1e into TeamWiseFlow:master Jul 21, 2026
2 checks passed
bigbrother666sh added a commit that referenced this pull request Jul 21, 2026
…被误判 unbound (#453)

macOS 用户 v5.6.0 升级模式跑到 [9/11] Placing config template 报
`reason?: unbound variable`(line 1174)。本地 Linux bash 5 同代码正常,
差异在 macOS 自带 /bin/bash 3.2。

根因(真因,非 PR #451 误判的绑定坑):bash 3.2 在 C locale 下把
未加花括号的 `$var` 后接多字节字符(全角()/→)的字节也算进变量名查找,
`$reason)` 被查成 `reason)` → unbound,报错里 `?` 是全角 )的 C locale 渲染。
PR #451 的预绑定是对错因下药(绑定从来没问题),花括号才是真修。

修法:
- place_config_template 内所有 $var 引用一律 ${var} 加花括号
- 多字节标点改 ASCII:→ 改 ->,()改 ()
- 每个变量单独 local 声明再纯赋值预绑(belt-and-suspenders,规避多变量一行 local 坑)
- 顺手 brace 另 4 处同类风险引用(camoufox/weixin/awada warn、bind_weixin warn)

install.ps1 有 8 处类似但 PowerShell 原生 UTF-8 解析无此坑,不动。

Co-authored-by: codes-factory-of-bg <bigbrother666@wiseflow.tech>
@bigbrother666sh
bigbrother666sh deleted the fix/install-backup-unbound-bash32 branch July 22, 2026 14:41
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.

2 participants