You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] Tilde for known-but-unlisted system users expands to '/' instead of staying unexpanded #1657
P3-low低:优化、文档、远期规划,有机会再做area:expansionword splitting, quote removal, parameter/brace expansionbugSomething isn't workinggnu-baselineTracked by the GNU Bash 5.3.0 true-baseline ledgerplatform:windowsDivergence specific to the Windows build
When a username is not resolvable via the user database, GNU leaves the tilde word unexpanded; rubash expands a subset of well-known system names (root, daemon, bin, …) to /.
Environment: Termux (no /etc/passwd entries for these users), niu 1.4.4 / rubash d15a02d vs GNU bash 5.3.20.
Regression seed
echo~daemon
# GNU: ~daemon (unexpanded — no such user)# niu: /
Same for ~root, ~bin, and suffixed ~root/x (niu //x, GNU ~root/x).
Measured (timeout 5 <shell> --noprofile --norc -c, 3/3 each side)
word
niu
GNU
~nosuchuser123
unexpanded (agree)
unexpanded
~root / ~daemon / ~bin
/
unexpanded
~root/x
//x
~root/x
~, ~+, /data/data/com.termux/files/home
agree
agree
So lookup failure is handled correctly for arbitrary names, but hardcoded system names bypass the lookup-failure path and map to /.
Dup-check
Searched all 73 open issues for tilde/home/expand/passwd — no match. Grep of labels harvest files for tilde — no hit. Known-multibyte/expansion issues (#1058, #1061) are unrelated. Note: on systems where these users do resolve, both shells presumably agree, so this bites on minimal/container user databases.
Found by differential fuzz round 4 (seed 12377, 400 snippets).
Note for triage: this reproduces the exact table/words of open #1233 (~root/~daemon/~bin → /, ~root/x → //x, arbitrary names pass through) on the same Termux empty-passwd environment — likely the same hardcoded-fallback root cause. Consider closing as duplicate of #1233; leaving open for owner decision.
Adjudication (fix7/mopup-c cluster, full evidence in ~/workspace/rubash-fix7/clusters/mopup-c/REPORT.md §#1657):
All tilde expansion in the repo funnels into passwd_home_for_user, which on unix is a faithful getpwnam_r lookup (not found → tilde left as-is). There is no hardcoded system-user table anywhere in src/ (grep-verified).
On this machine (glibc), rubash and GNU bash 5.3.20 agree item-for-item: ~daemon → /usr/sbin, ~root → /root, ~nosuchuser123 unexpanded — both sides read the same passwd database, and GNU's tilde code pastes pw_dir verbatim just like we do.
The reported Termux divergence can therefore only enter through the platform libc: if bionic returns pw_dir="/" for its synthesized user entries, getpwnam_r cannot distinguish a synthesized entry from a real one, and any code-side "correction" would deviate from GNU's algorithm itself.
Disposition: not an in-repo bug on current evidence. The in-repo invariant (faithful getpwnam lookup) is pinned by tests/issue1657_tilde_system_user_regressions.rs, landing with the mopup-c slice as Refs, not Fixes.
Reclassification path: on a real Termux device, run a C probe of getpwnam("daemon") and record pw_dir. If bionic indeed returns /, this is a platform-database face and this issue should close as such; if it returns a real home, reopen with that evidence and it becomes an engine bug again.
So on a system where the passwd database is faithful, rubash already matches GNU, including unknown-user-kept-verbatim.
What I ruled out in rubash's own code (master and the issue's d15a02d):
There is no hardcoded system-user table anywhere in the repo (grep for daemon across all sources finds nothing but comments, at both revisions). The issue title's "hardcoded system names" is an inference, not something present in code.
Every ~user path funnels into one function, passwd_home_for_user (src/expand/tilde/tilde.rs), which on unix is a plain getpwnam_r call: status != 0 or NULL result → None → the caller keeps the word verbatim. No / fallback exists in the tilde module or its callers (expand_word.rs, shell_options.rs, subscript_expansion.rs all keep the word on None).
GNU's own rule (vendored third_party/bash/lib/tilde/tilde.c:379-403, tilde_expand_word) is exactly the same: getpwnam NULL → savestring(filename), no extra check. So on one shared database, getpwnam and getpwnam_r must agree — and on glibc they do.
Where the divergence must therefore live: Bionic's getpwnam_r vs getpwnam on Termux. GNU bash calls getpwnam; rubash calls getpwnam_r. If Bionic's _r variant returns a stub entry (pw_dir /) for these names while getpwnam returns NULL, rubash faithfully reports what libc told it, and no rubash-side table is involved. This VM has no Android/Bionic environment to confirm that, so I am not shipping a guessed fix — a hardcoded denylist of root/daemon/bin would be whack-a-mole (it would break systems where daemon legitimately resolves, e.g. glibc /usr/sbin above) and violates the repo's no-blacklist rule.
What would settle it (one command on Termux):
/* probe: getpwnam vs getpwnam_r for root/daemon/bin/nosuchuser123 */
If the probe shows getpwnam("daemon") = NULL but getpwnam_r("daemon") returning pw_dir /, the fix belongs in the lookup call (e.g. prefer getpwnam on Bionic, or validate the _r result), and I'll implement it with a regression test. If both agree on Termux too, the niu 1.4.4 binary's environment needs a second look (e.g. a passwd file the release resolves differently).
Leaving this open and unassigned-to-a-fix until that probe result lands; the glibc matrix above is the regression baseline either way.
Follow-up: the actual probe program referenced above (the previous comment's code block was a placeholder). Save as probe.c, run on Termux with cc probe.c -o probe && ./probe:
P3-low低:优化、文档、远期规划,有机会再做area:expansionword splitting, quote removal, parameter/brace expansionbugSomething isn't workinggnu-baselineTracked by the GNU Bash 5.3.0 true-baseline ledgerplatform:windowsDivergence specific to the Windows build
Activity
caomengxuan666 commentedon Oct 25, 2026
Note for triage: this reproduces the exact table/words of open #1233 (
~root/~daemon/~bin→/,~root/x→//x, arbitrary names pass through) on the same Termux empty-passwd environment — likely the same hardcoded-fallback root cause. Consider closing as duplicate of #1233; leaving open for owner decision.caomengxuan666 commentedon Oct 25, 2026
Adjudication (fix7/mopup-c cluster, full evidence in
~/workspace/rubash-fix7/clusters/mopup-c/REPORT.md§#1657):passwd_home_for_user, which on unix is a faithfulgetpwnam_rlookup (not found → tilde left as-is). There is no hardcoded system-user table anywhere insrc/(grep-verified).~daemon→/usr/sbin,~root→/root,~nosuchuser123unexpanded — both sides read the same passwd database, and GNU's tilde code pastespw_dirverbatim just like we do.pw_dir="/"for its synthesized user entries,getpwnam_rcannot distinguish a synthesized entry from a real one, and any code-side "correction" would deviate from GNU's algorithm itself.Disposition: not an in-repo bug on current evidence. The in-repo invariant (faithful getpwnam lookup) is pinned by
tests/issue1657_tilde_system_user_regressions.rs, landing with the mopup-c slice asRefs, notFixes.Reclassification path: on a real Termux device, run a C probe of
getpwnam("daemon")and recordpw_dir. If bionic indeed returns/, this is a platform-database face and this issue should close as such; if it returns a real home, reopen with that evidence and it becomes an engine bug again.arookieofc commentedon Oct 25, 2026
Investigation (not a fix yet — needs a Termux-side probe before any code change):
What I verified on a glibc host (rubash master vs GNU bash 5.2, both directions agree):
echo ~daemon ~root ~bin ~nosuchuser123 ~root/x ~→rubash:
/usr/sbin /root /bin ~nosuchuser123 /root/x /home/hatchGNU: identical, byte for byte.
What I ruled out in rubash's own code (master and the issue's d15a02d):
daemonacross all sources finds nothing but comments, at both revisions). The issue title's "hardcoded system names" is an inference, not something present in code.~userpath funnels into one function,passwd_home_for_user(src/expand/tilde/tilde.rs), which on unix is a plaingetpwnam_rcall: status != 0 or NULL result → None → the caller keeps the word verbatim. No/fallback exists in the tilde module or its callers (expand_word.rs,shell_options.rs,subscript_expansion.rsall keep the word on None).third_party/bash/lib/tilde/tilde.c:379-403,tilde_expand_word) is exactly the same:getpwnamNULL →savestring(filename), no extra check. So on one shared database,getpwnamandgetpwnam_rmust agree — and on glibc they do.Where the divergence must therefore live: Bionic's
getpwnam_rvsgetpwnamon Termux. GNU bash callsgetpwnam; rubash callsgetpwnam_r. If Bionic's_rvariant returns a stub entry (pw_dir/) for these names whilegetpwnamreturns NULL, rubash faithfully reports what libc told it, and no rubash-side table is involved. This VM has no Android/Bionic environment to confirm that, so I am not shipping a guessed fix — a hardcoded denylist of root/daemon/bin would be whack-a-mole (it would break systems wheredaemonlegitimately resolves, e.g. glibc/usr/sbinabove) and violates the repo's no-blacklist rule.What would settle it (one command on Termux):
/* probe: getpwnam vs getpwnam_r for root/daemon/bin/nosuchuser123 */If the probe shows
getpwnam("daemon") = NULLbutgetpwnam_r("daemon")returning pw_dir/, the fix belongs in the lookup call (e.g. prefergetpwnamon Bionic, or validate the_rresult), and I'll implement it with a regression test. If both agree on Termux too, theniu 1.4.4binary's environment needs a second look (e.g. a passwd file the release resolves differently).Leaving this open and unassigned-to-a-fix until that probe result lands; the glibc matrix above is the regression baseline either way.
arookieofc commentedon Oct 25, 2026
Follow-up: the actual probe program referenced above (the previous comment's code block was a placeholder). Save as
probe.c, run on Termux withcc probe.c -o probe && ./probe:Interpretation:
getpwnam(daemon) = (null)butgetpwnam_rreturningdir=/→ the divergence is in Bionic's_rvariant; fix belongs in rubash's lookup call./→ the Termux passwd database itself carries those entries, and GNU bash on Termux would need a second look too.Merge pull request #2008 from unixwin/fix/expansion-batch-1993-1981-1…