From patchwork Tue Apr 25 08:18:08 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: 754635 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 3wBx1y6P2Dz9s85 for ; Tue, 25 Apr 2017 18:19:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 88175C21C33; Tue, 25 Apr 2017 08:18:58 +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 1A5EDC21C33; Tue, 25 Apr 2017 08:18:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AE4F4C21C33; Tue, 25 Apr 2017 08:18:54 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by lists.denx.de (Postfix) with ESMTPS id 5EF6AC21C25 for ; Tue, 25 Apr 2017 08:18:54 +0000 (UTC) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v3P8HF7H012505; Tue, 25 Apr 2017 10:18:51 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 29yva6hkst-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 25 Apr 2017 10:18:51 +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 63A1538; Tue, 25 Apr 2017 08:18:50 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4552610F4; Tue, 25 Apr 2017 08:18:50 +0000 (GMT) Received: from localhost (10.201.23.67) by webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Tue, 25 Apr 2017 10:18:50 +0200 From: To: , , , Date: Tue, 25 Apr 2017 10:18:08 +0200 Message-ID: <1493108288-24058-1-git-send-email-nicolas.le.bayon@st.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.201.23.67] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-25_04:, , signatures=0 Cc: jean-philippe.romain@st.com Subject: [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" 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(-) 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); }