Skip to content

[bug] ~user expands unknown usernames to / (or /data) instead of leaving literal #1233

Closed

Description

@caomengxuan666

[bug] ~user expands unknown usernames to / (or /data) instead of leaving literal

On a system with an empty user database (/etc/passwd empty, Termux), GNU leaves ~unknown unexpanded. niu invents a home directory:

echo ~root      # GNU: ~root    | niu: /
echo ~daemon    # GNU: ~daemon   | niu: /
echo ~nobody    # GNU: ~nobody   | niu: /
echo ~bin       # GNU: ~bin     | niu: /
echo ~system    # GNU: ~system   | niu: /
echo ~shell     # GNU: ~shell    | niu: /
echo ~root/x    # GNU: ~root/x   | niu: //x
echo ~u0_a123   # GNU: ~u0_a123  | niu: /data
echo ~u0_a256   # GNU: ~u0_a256  | niu: /data  (even the *current* uid name -> /data, not $HOME)
echo ~nouser_xyz # both: ~nouser_xyz (literal — some names pass through)

Pattern: a hardcoded Android fallback table (root/daemon/… → /, u0_a* → /data) is consulted instead of (or before) the user database, and failure falls back to / rather than leaving the word literal. Safety-relevant: rm -rf ~typo/dir would resolve to //dir under niu. On desktop Linux with a real /etc/passwd the outcome may differ — needs a check there too — but the no-such-user case must stay literal per GNU.

Env: niubash 1.4.4 / rubash engine 1b14a3d, GNU bash 5.3.20 aarch64-linux-android as oracle (empty /etc/passwd).

Activity

  1. added
    bug
    gnu-baseline
    P2-medium
    area:expansion
    on Oct 23, 2026
  2. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Same fallback table fires in assignment/declare/tempenv positions (verified niu 1.4.4 vs bash 5.3.20 Termux, 3/3): v=~root; echo "v=$v" → bash ~root, niu /; v=~root/x → //x; declare dr=~root → /; A=~root env | grep A → /. GNU leaves all literal (empty /etc/passwd). No new issue — same root, additional slots.

  3. caomengxuan666 commented on Oct 24, 2026

    @caomengxuan666
    MemberAuthor

    复核结论:未复现,按证据关单。glibc 基线实测(x6 簇复核):~root→/root、~daemon→/usr/sbin、~bin→/bin,均为真实 getpwnam 结果、与 GNU bash 5.3.20 逐字节一致;~nosuchuser_xyz、~u0_a123 两边都保持字面。代码走真实用户数据库查询,issue 所述硬编码 Android 回退表在 glibc 路径上不存在。若在 Android/设备环境仍可复现,请附设备环境与复现命令重开。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2-mediumarea:expansionbuggnu-baseline

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions