Fix abort in clickhouse-client --login when no host is passed explicitly

`Client::login` read `hosts_and_ports.front()`, but `hosts_and_ports` is only
filled from explicit `--host` arguments; the default host is added later, in
`Client::connect`. Running `clickhouse client --login` without `--host` (e.g.
with the host coming from `--connection`, the config file, or the
`CLICKHOUSE_HOST` environment variable) failed a libc++ hardening assertion:
`front() called on an empty vector`.

Resolve the host from the configuration when `hosts_and_ports` is empty, the
same way `connect` does.

Also fix the client docs, which listed the option as `login` instead of
`--login`.

Closes: https://github.com/ClickHouse/ClickHouse/issues/103603

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Christoph Wurm
2026-07-13 15:17:44 +01:00
co-authored by Claude Fable 5
parent e470a89a29
commit e5f80bbc8d
4 changed files with 21 additions and 2 deletions
+6 -1
View File
@@ -482,7 +482,12 @@ catch (...)
#if USE_JWT_CPP && USE_SSL
void Client::login()
{
std::string host = hosts_and_ports.front().host;
/// `hosts_and_ports` is filled from explicit --host arguments only; the default host is added
/// later, in `connect`. A host given via config, --connection or the environment is still
/// sitting in the configuration at this point.
std::string host = hosts_and_ports.empty()
? getClientConfiguration().getString("host", "localhost")
: hosts_and_ports.front().host;
std::string auth_url = getClientConfiguration().getString("oauth-url", "");
std::string client_id = getClientConfiguration().getString("oauth-client-id", "");
std::string audience = getClientConfiguration().getString("oauth-audience", "");