]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Lib: Fix handling of buffers in timestamp formatting
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 12 Apr 2021 15:01:31 +0000 (17:01 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 12 Apr 2021 15:01:31 +0000 (17:01 +0200)
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

index a5abbcc46896b25cd015ca18789c3f7a2b2a3403..381163d0b09013fa1ceead5e2a52dd2ade17827a 100644 (file)
@@ -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))