From 9c41e1ca3e93d4498eaa085139caf1545e08c1d8 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Mon, 12 Apr 2021 17:01:31 +0200 Subject: 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. --- lib/timer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/timer.c') 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)) -- cgit v1.2.3