Skip to contentSkip to conversation

ui: fix vc_chr_write call in text_console_do_init

PATCH New Gerd Hoffmann 1 participant 1 message Jul 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui: fix vc_chr_write call in text_console_do_init

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.

---
 ui/console.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
ui/console.c +4 -4
index 865fa3263597..5ba0f21831cb 100644
@@ -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;
     }
 
Signature · 1 line
2.18.4