From 45b0f52a42ebd84edbe89016aea6129b0721f097 Mon Sep 17 00:00:00 2001 From: Anders Betts Date: Fri, 18 Sep 2026 13:32:05 +0200 Subject: bokftui: fix self-copy that emptied the username on password login try_login is called with a->username as the user; snprintf with overlapping source and destination is undefined and produced "" on glibc, so config_save wrote 'user=' and later reloads could not auto-login. Copy through a temporary, carry BOKFD_USER on reload and never persist an empty user. --- clients/bokftui.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/clients/bokftui.c b/clients/bokftui.c index be94429..50e5c3f 100644 --- a/clients/bokftui.c +++ b/clients/bokftui.c @@ -4011,6 +4011,8 @@ static void do_reload(struct app *a, const char *self) setenv("BOKFD_SESSION", a->session, 1); if (a->password[0]) setenv("BOKFD_PASSWORD", a->password, 1); + if (a->username[0]) + setenv("BOKFD_USER", a->username, 1); tui_log("reload: screen=%s org=%lld fy=%lld", g_reload_scene, (long long)a->org, (long long)a->fy); endwin(); @@ -4141,7 +4143,9 @@ static void config_save(const struct app *a) FILE *f = fopen(path, "w"); if (!f) return; - fprintf(f, "server=%s\nuser=%s\n", a->socket, a->username); + fprintf(f, "server=%s\n", a->socket); + if (a->username[0]) + fprintf(f, "user=%s\n", a->username); fclose(f); chmod(path, 0600); } @@ -4201,8 +4205,13 @@ static int try_login(struct app *a, const char *user, const char *pass, return -1; } snprintf(a->session, sizeof a->session, "%s", session); - if (user && *user) - snprintf(a->username, sizeof a->username, "%s", user); + if (user && *user) { + /* callers may pass a->username itself; snprintf with overlapping + source and destination is undefined and yields "" on glibc */ + char ubuf[64]; + snprintf(ubuf, sizeof ubuf, "%s", user); + snprintf(a->username, sizeof a->username, "%s", ubuf); + } free(session); if (token && *token) { char *resp = -- cgit v1.3