From f22bc5171f733d1f9a6f3daeab8233386e79c320 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 10 Aug 2025 11:40:03 +0300 Subject: allow messages to be of arbitrary length: fixes crashes * Messages can be arbitrarily long, e.g. the following could provoke crashes in interactive mode `1000<@I/X/> HX$` It's hard to turn into a test case, though, as you could always increase the buffer size in teco_interface_msg(). * The message length is now only limited by RAM. * This implementation is less effective, but code opting for efficience, including all programmable user messages, should not rely on the printf-API anyway but use teco_interface_msg_literal(). --- src/interface.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/interface.c b/src/interface.c index cfc8279..8685990 100644 --- a/src/interface.c +++ b/src/interface.c @@ -20,6 +20,7 @@ #endif #include +#include #include #include @@ -87,19 +88,13 @@ teco_interface_undo_set_clipboard(const gchar *name, gchar *str, gsize len) void teco_interface_msg(teco_msg_t type, const gchar *fmt, ...) { - gchar buf[512]; va_list ap; va_start(ap, fmt); - /* - * If the buffer could ever be exceeded, perhaps - * use g_strdup_vprintf() instead. - */ - gint len = g_vsnprintf(buf, sizeof(buf), fmt, ap); - g_assert(0 <= len && len < sizeof(buf)); + g_autofree gchar *buf = g_strdup_vprintf(fmt, ap); va_end(ap); - teco_interface_msg_literal(type, buf, len); + teco_interface_msg_literal(type, buf, strlen(buf)); } /** -- cgit v1.2.3