diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-08-10 11:40:03 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-08-10 11:40:03 +0300 |
commit | f22bc5171f733d1f9a6f3daeab8233386e79c320 (patch) | |
tree | e439f502215548827d81b5cc8fb192fab7c311f6 | |
parent | 20b5a04370ac987807af73526b22dfe6e8a08a3d (diff) | |
download | sciteco-f22bc5171f733d1f9a6f3daeab8233386e79c320.tar.gz |
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().
-rw-r--r-- | src/interface.c | 11 |
1 files 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 <stdarg.h> +#include <string.h> #include <stdio.h> #include <glib.h> @@ -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)); } /** |