diff --git a/plugins/cli/cli.c b/plugins/cli/cli.c index 07d4d39..a28fb3a 100644 --- a/plugins/cli/cli.c +++ b/plugins/cli/cli.c @@ -732,9 +732,13 @@ cli_send(void *ctx, const struct sp_conv *conv, struct sp_reply *out, time_t tt = (time_t)soonest; struct tm tm; - if (soonest > 0) - strftime(when, sizeof(when), "%Y-%m-%d %H:%M", - localtime_r(&tt, &tm)); + if (soonest > 0) { + /* an unrepresentable time must not become a wrong + * one: the operator reads this as "come back at" */ + if (localtime_r(&tt, &tm) != NULL) + strftime(when, sizeof(when), + "%Y-%m-%d %H:%M", &tm); + } if (tried == 0) sp_buf_clear(err); sp_buf_printf(err, "%scli: every account at its usage limit, " diff --git a/src/backend/agent.c b/src/backend/agent.c index b2a2796..de9bbee 100644 --- a/src/backend/agent.c +++ b/src/backend/agent.c @@ -372,7 +372,17 @@ sp_limit_wait_default(void *ctx, long until, const char *why) if (until - now > cap) return 0; - strftime(when, sizeof(when), "%Y-%m-%d %H:%M", localtime_r(&tt, &tm)); + /* + * localtime_r() returns NULL for a value it cannot represent - and the + * value is not ours: a cooldown file can hold anything, a provider's + * "ready_at=" can be absurd. strftime() would then format whatever the + * uninitialised tm holds, and the operator reads a limit that lifts at + * "219250468--1414812756--1414812757". "?" is no time instead of a + * wrong one, the same answer the foreign plugin gives. + */ + strcpy(when, "?"); + if (localtime_r(&tt, &tm) != NULL) + strftime(when, sizeof(when), "%Y-%m-%d %H:%M", &tm); fprintf(stderr, "splinter: usage limit reached (%.80s); continuing at %s\n", why != NULL ? why : "", when); while ((long)time(NULL) < until) diff --git a/src/backend/engine.c b/src/backend/engine.c index facdb6b..e6c25f7 100644 --- a/src/backend/engine.c +++ b/src/backend/engine.c @@ -1226,7 +1226,10 @@ engine_limit_wait(void *ctx, long until, const char *why) (void)why; if (until - (long)time(NULL) > wait) return 0; - strftime(when, sizeof(when), "%a %H:%M", localtime_r(&tt, &tm)); + /* an unrepresentable time must not become a wrong one (see agent.c) */ + strcpy(when, "?"); + if (localtime_r(&tt, &tm) != NULL) + strftime(when, sizeof(when), "%a %H:%M", &tm); snprintf(line, sizeof(line), sp_t("ui.limit_wait"), when); ev_push(e, SP_EV_NOTE, 0, line, NULL); while ((long)time(NULL) < until && !e->cancel) { diff --git a/src/backend/session.c b/src/backend/session.c index b01bc21..3e1f626 100644 --- a/src/backend/session.c +++ b/src/backend/session.c @@ -1113,8 +1113,10 @@ sp_session_folder_history(const char *dir, const char *cwd, unsigned limit, size_t turns = 0; char last[512] = ""; - (void)localtime_r(&when, &tm); - strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M", &tm); + if (localtime_r(&when, &tm) != NULL) + strftime(stamp, sizeof(stamp), "%Y-%m-%d %H:%M", &tm); + else + snprintf(stamp, sizeof(stamp), "?"); snprintf(path, sizeof(path), "%.500s/%.120s.jsonl", dir, found[i].name); f = fopen(path, "r");