time: an unrepresentable time is "?", not an uninitialised struct tm
Four places formatted a time with strftime(localtime_r(&tt, &tm)) and threw the NULL away. When localtime_r cannot represent the value - a cooldown file can hold anything - tm is untouched and strftime formats whatever the stack held: the operator read a limit that lifts at "219250468--1414812756--1414812757", and a NULL deref in the die-hard case. agent.c, engine.c, session.c and plugins/cli now check the return and fall back to "?", the answer the foreign plugin already gives for a time it does not know. Found by review; the strftime call site is the same shape in all four.
This commit is contained in:
1 parent
407f073ae3
commit
4f7255548d
4 files changed
+26
-7
No files matched your search
+7
-3
@@ -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, "
|
||||
|
||||
Reference in new issue
Block a user