From patchwork Tue May 9 15:58:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nicolas.le.bayon@st.com X-Patchwork-Id: 760213 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wMkZ00FnBz9s3T for ; Wed, 10 May 2017 01:58:47 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B77E8C21C5A; Tue, 9 May 2017 15:58:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 09DE5C21C5A; Tue, 9 May 2017 15:58:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C9D8FC21C5A; Tue, 9 May 2017 15:58:40 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by lists.denx.de (Postfix) with ESMTPS id 72953C21C43 for ; Tue, 9 May 2017 15:58:40 +0000 (UTC) Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v49Fs7Dr002690; Tue, 9 May 2017 17:58:38 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 2a9cuy7xjb-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 09 May 2017 17:58:38 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7AD3738; Tue, 9 May 2017 15:58:37 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag6node2.st.com [10.75.127.17]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5AC97249F; Tue, 9 May 2017 15:58:37 +0000 (GMT) Received: from SFHDAG6NODE3.st.com (10.75.127.18) by SFHDAG6NODE2.st.com (10.75.127.17) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 9 May 2017 17:58:37 +0200 Received: from SFHDAG6NODE3.st.com ([fe80::d04:5337:ab17:b6f6]) by SFHDAG6NODE3.st.com ([fe80::d04:5337:ab17:b6f6%20]) with mapi id 15.00.1178.000; Tue, 9 May 2017 17:58:36 +0200 From: Nicolas LE BAYON To: "u-boot@lists.denx.de" , "lukma@denx.de" , "marex@denx.de" Thread-Topic: [U-Boot][PATCH v7] usb: gadget: avoid variable name clipping in cb_getvar Thread-Index: AQHSvZyR6pWrOWsM0E2DhPTT4j6mGqHsPpqw Date: Tue, 9 May 2017 15:58:36 +0000 Message-ID: <25b36f7ec9f5410da8b9c0da2a498daf@SFHDAG6NODE3.st.com> References: <1493108288-24058-1-git-send-email-nicolas.le.bayon@st.com> In-Reply-To: <1493108288-24058-1-git-send-email-nicolas.le.bayon@st.com> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.75.127.47] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-09_13:, , signatures=0 Cc: Jean-philippe ROMAIN Subject: Re: [U-Boot] [PATCH v7] usb: gadget: avoid variable name clipping in cb_getvar X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Hi, A kind reminder to look at this patch (already reviewed by Marek and acked by Lukasz), and if possible to put it in the next pull list, or the one after is timing is too short. Thanks in advance for your time Best Regards Nicolas -----Original Message----- From: Nicolas LE BAYON Sent: mardi 25 avril 2017 10:18 To: Nicolas LE BAYON ; u-boot@lists.denx.de; lukma@denx.de; marex@denx.de Cc: nlebayon@gmail.com; Patrice CHOTARD ; Jean-philippe ROMAIN Subject: [U-Boot][PATCH v7] usb: gadget: avoid variable name clipping in cb_getvar From: Nicolas Le Bayon Instead of using a fixed-size array to store variable name, preferring a dynamic allocation treats correctly all variable name lengths. Variable names are growing through releases and features. By this way, name clipping is prevented. Signed-off-by: Nicolas Le Bayon Reviewed-by: Marek Vasut Acked-by: Lukasz Majewski --- Changes in v2: - instead of using a bigger fixed size, use malloc to fit with size needs Changes in v3: - v2 was an error (intermediate version), so propose a complete one Changes in v4: - be more explicit and detailed in label and description fields - remove intermediate variable only used one time - be more explicit in error message - fix indent issue Changes in v5: - drop an unuseful error() call Changes in v6: - add Marek review approval Changes in v7: - add Lukasz ack approval drivers/usb/gadget/f_fastboot.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index 2160b1c..7cd6d24 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -432,9 +432,15 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) else strcpy(response, "FAILValue not set"); } else { - char envstr[32]; + char *envstr; - snprintf(envstr, sizeof(envstr) - 1, "fastboot.%s", cmd); + envstr = malloc(strlen("fastboot.") + strlen(cmd) + 1); + if (!envstr) { + fastboot_tx_write_str("FAILmalloc error"); + return; + } + + sprintf(envstr, "fastboot.%s", cmd); s = getenv(envstr); if (s) { strncat(response, s, chars_left); @@ -442,6 +448,8 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) printf("WARNING: unknown variable: %s\n", cmd); strcpy(response, "FAILVariable not implemented"); } + + free(envstr); } fastboot_tx_write_str(response); }