Skip to content

Commit 1859518

Browse files
committed
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. Reported-by: Wenxiang Qian <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]> Message-id: [email protected]
1 parent 480324e commit 1859518

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ui/console.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,12 +2184,12 @@ static void text_console_do_init(Chardev *chr, DisplayState *ds)
21842184
text_console_resize(s);
21852185

21862186
if (chr->label) {
2187-
char msg[128];
2188-
int len;
2187+
char *msg;
21892188

21902189
s->t_attrib.bgcol = QEMU_COLOR_BLUE;
2191-
len = snprintf(msg, sizeof(msg), "%s console\r\n", chr->label);
2192-
vc_chr_write(chr, (uint8_t *)msg, len);
2190+
msg = g_strdup_printf("%s console\r\n", chr->label);
2191+
vc_chr_write(chr, (uint8_t *)msg, strlen(msg));
2192+
g_free(msg);
21932193
s->t_attrib = s->t_attrib_default;
21942194
}
21952195

0 commit comments

Comments
 (0)