From e3d60bc7c6f26b889686ab91f7062f6a79df2494 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Thu, 10 Mar 2016 10:35:24 +0800 Subject: [PATCH] usb: fix unbound stack usage for usb_mtp_add_str Use heap instead of stack. Signed-off-by: Peter Xu Signed-off-by: Gerd Hoffmann --- hw/usb/dev-mtp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 7391783193..62fb7cd518 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -718,7 +718,7 @@ static void usb_mtp_add_wstr(MTPData *data, const wchar_t *str) static void usb_mtp_add_str(MTPData *data, const char *str) { uint32_t len = strlen(str)+1; - wchar_t wstr[len]; + wchar_t *wstr = g_new(wchar_t, len); size_t ret; ret = mbstowcs(wstr, str, len); @@ -727,6 +727,8 @@ static void usb_mtp_add_str(MTPData *data, const char *str) } else { usb_mtp_add_wstr(data, wstr); } + + g_free(wstr); } static void usb_mtp_add_time(MTPData *data, time_t time)