All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ui: fix vc_chr_write call in text_console_do_init
@ 2020-07-01 18:18 Gerd Hoffmann
  0 siblings, 0 replies; only message in thread
From: Gerd Hoffmann @ 2020-07-01 18:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

In case the string doesn't fit into the buffer snprintf returns the size
it would need, so len can be larger than the buffer.  Fix this by simply
using g_strdup_printf() instead of a static buffer.

Reported-by: Wenxiang Qian <leonwxqian@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/console.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index 865fa3263597..5ba0f21831cb 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -2184,12 +2184,12 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)
     text_console_resize(s);
 
     if (chr->label) {
-        char msg[128];
-        int len;
+        char *msg;
 
         s->t_attrib.bgcol = QEMU_COLOR_BLUE;
-        len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label);
-        vc_chr_write(chr, (uint8_t *)msg, len);
+        msg = g_strdup_printf("%s console\r\n", chr->label);
+        vc_chr_write(chr, (uint8_t *)msg, strlen(msg));
+        g_free(msg);
         s->t_attrib = s->t_attrib_default;
     }
 
-- 
2.18.4



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-01 18:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 18:18 [PATCH] ui: fix vc_chr_write call in text_console_do_init Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.