From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adpoQ-0004Y9-25 for qemu-devel@nongnu.org; Wed, 09 Mar 2016 20:54:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adpoM-0003yi-0s for qemu-devel@nongnu.org; Wed, 09 Mar 2016 20:54:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51060) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adpoL-0003yU-SR for qemu-devel@nongnu.org; Wed, 09 Mar 2016 20:54:45 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 769F9C0005D8 for ; Thu, 10 Mar 2016 01:54:45 +0000 (UTC) Date: Thu, 10 Mar 2016 09:54:41 +0800 From: Fam Zheng Message-ID: <20160310015441.GF23632@ad.usersys.redhat.com> References: <1457503813-31631-1-git-send-email-peterx@redhat.com> <1457503813-31631-2-git-send-email-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1457503813-31631-2-git-send-email-peterx@redhat.com> Subject: Re: [Qemu-devel] [PATCH 1/2] usb: fix unbound stack usage for usb_mtp_add_str List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Xu Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, kraxel@redhat.com On Wed, 03/09 14:10, Peter Xu wrote: > Use heap instead of stack. > > Signed-off-by: Peter Xu > --- > 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 7391783..cf63fd0 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_malloc(sizeof(wchar_t) * len); I think it is better to use g_new() in this case. Fam > 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) > -- > 2.4.3 > >