summaryrefslogtreecommitdiff
path: root/lib/timer.c
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2021-04-12 17:01:31 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2021-04-12 17:01:31 +0200
commit9c41e1ca3e93d4498eaa085139caf1545e08c1d8 (patch)
treeb8ab505a29b7b0e8a0f0fc1968999fc60f445e35 /lib/timer.c
parenta2277975d787fb388e753432673acefd69454b1a (diff)
Lib: Fix handling of buffers in timestamp formatting
The code in tm_format_real_time() mixed up two buffers and their sizes, which may cause crash in MRT dumping code. Thanks to Piotr Wydrych for the bugreport.
Diffstat (limited to 'lib/timer.c')
-rw-r--r--lib/timer.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/timer.c b/lib/timer.c
index a5abbcc4..381163d0 100644
--- a/lib/timer.c
+++ b/lib/timer.c
@@ -365,8 +365,9 @@ tm_format_real_time(char *x, size_t max, const char *fmt, btime t)
if (!localtime_r(&ts, &tm))
return 0;
- byte tbuf[TM_DATETIME_BUFFER_SIZE];
- if (!strfusec(tbuf, max, fmt, t2))
+ size_t tbuf_size = MIN(max, 4096);
+ byte *tbuf = alloca(tbuf_size);
+ if (!strfusec(tbuf, tbuf_size, fmt, t2))
return 0;
if (!strftime(x, max, tbuf, &tm))