From 1529540ea2870ac384ce8cd3633d245b7e71d5f9 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 6 Dec 2026 02:21:18 +0000 Subject: [PATCH] misc: Use getpwnam_r in ssh_path_expand_tilde `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 --- src/misc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/misc.c b/src/misc.c index f6f74108..250c9ffb 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1204,17 +1204,20 @@ char *ssh_path_expand_tilde(const char *d) #ifdef _WIN32 return strdup(d); #else + struct passwd pwd; struct passwd *pw = NULL; + char buf[NSS_BUFLEN_PASSWD] = {0}; size_t s = p - d; char u[128]; + int rc; if (s >= sizeof(u)) { return NULL; } memcpy(u, d, s); u[s] = '\0'; - pw = getpwnam(u); - if (pw == NULL) { + rc = getpwnam_r(u, &pwd, buf, NSS_BUFLEN_PASSWD, &pw); + if (rc != 0 || pw == NULL) { return NULL; } ld = strlen(p);