Skip to content

misc: Use getpwnam_r in ssh_path_expand_tilde - #20

Open
alexey-milovidov wants to merge 1 commit into
ClickHouse/libssh-0.12.2from
tilde-expansion-getpwnam-r
Open

alexey-milovidov wants to merge 1 commit into
ClickHouse/libssh-0.12.2from
tilde-expansion-getpwnam-r

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

ssh_path_expand_tilde calls getpwnam for a ~user/ path. getpwnam returns a pointer to a static object, so it is not thread-safe; ClickHouse traps it at run time (base/harmful), and the libc that ClickHouse links statically is about to lose it (ClickHouse/musl#31).

The call is reachable in clickhouse-client, which reads the ssh client configuration (ssh_options_parse_config): Include ~user/..., IdentityAgent ~user/... and ControlPath ~user/... are expanded while the configuration is parsed.

Use getpwnam_r with a buffer on the stack, the same way ssh_get_user_home_dir_internal in the same file uses getpwuid_r.

The ClickHouse side is in ClickHouse/ClickHouse#138028, which pins this branch.

🤖 Generated with Claude Code

`getpwnam` returns a pointer to a static object, so it is not thread-safe.
ClickHouse traps it at run time (`base/harmful`), and its libc does not
have it anymore. `ssh_path_expand_tilde` reaches it for a `~user/` path in
the ssh client configuration (`Include`, `IdentityAgent`, `ControlPath`),
which `clickhouse-client` reads.

Use `getpwnam_r` with a buffer on the stack, the same way
`ssh_get_user_home_dir_internal` uses `getpwuid_r`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1529540. Configure here.

Comment thread src/misc.c
pw = getpwnam(u);
if (pw == NULL) {
rc = getpwnam_r(u, &pwd, buf, NSS_BUFLEN_PASSWD, &pw);
if (rc != 0 || pw == NULL) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tilde expansion fails for large entries

Medium Severity

getpwnam_r is called once with a fixed NSS_BUFLEN_PASSWD buffer, and any error, including ERANGE, returns NULL. On glibc that size is 1024 bytes and does not fit every passwd record. getpwnam grew its buffer, so oversized ~user paths that used to expand now fail and abort config parsing.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 1529540. Configure here.

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.

1 participant