summaryrefslogtreecommitdiff
path: root/clients/bokftui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-18 13:32:05 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-18 13:32:05 +0200
commit45b0f52a42ebd84edbe89016aea6129b0721f097 (patch)
treeb7d704803da50faa6fcdb7d5d2a570a39e4e526b /clients/bokftui.c
parent1c1cd947335d30e6f13d2d440da8a188c992d71a (diff)
downloadbokf-45b0f52a42ebd84edbe89016aea6129b0721f097.tar.gz
bokf-45b0f52a42ebd84edbe89016aea6129b0721f097.zip
bokftui: fix self-copy that emptied the username on password loginv0.1.23
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.
Diffstat (limited to 'clients/bokftui.c')
-rw-r--r--clients/bokftui.c15
1 files 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 =