Repository navigation
misc: Use getpwnam_r in ssh_path_expand_tilde - #20
Open
alexey-milovidov wants to merge 1 commit into
Open
alexey-milovidov wants to merge 1 commit into
alexey-milovidov wants to merge 1 commit into
Conversation
`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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
| pw = getpwnam(u); | ||
| if (pw == NULL) { | ||
| rc = getpwnam_r(u, &pwd, buf, NSS_BUFLEN_PASSWD, &pw); | ||
| if (rc != 0 || pw == NULL) { |
There was a problem hiding this comment.
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.
Reviewed by Cursor Bugbot for commit 1529540. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


ssh_path_expand_tildecallsgetpwnamfor a~user/path.getpwnamreturns 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/...andControlPath ~user/...are expanded while the configuration is parsed.Use
getpwnam_rwith a buffer on the stack, the same wayssh_get_user_home_dir_internalin the same file usesgetpwuid_r.The ClickHouse side is in ClickHouse/ClickHouse#138028, which pins this branch.
🤖 Generated with Claude Code