From patchwork Mon Apr 3 13:09:11 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: 746825 X-Patchwork-Delegate: l.majewski@samsung.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 3vy9pp2Rqbz9s84 for ; Wed, 5 Apr 2017 00:10:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1EF12C21CF0; Tue, 4 Apr 2017 13:56:54 +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.0 required=5.0 tests=none 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 B1CFDC21D94; Tue, 4 Apr 2017 13:29:24 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C27B2C21C48; Mon, 3 Apr 2017 13:09:17 +0000 (UTC) Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by lists.denx.de (Postfix) with ESMTPS id 80B22C21C33 for ; Mon, 3 Apr 2017 13:09:17 +0000 (UTC) Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v33D6rxU001124; Mon, 3 Apr 2017 15:09:15 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 29j1nvmx7w-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 03 Apr 2017 15:09:15 +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 A0C1F31; Mon, 3 Apr 2017 13:09:14 +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 866082979; Mon, 3 Apr 2017 13:09:14 +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.319.2; Mon, 3 Apr 2017 15:09:14 +0200 From: To: , , , Date: Mon, 3 Apr 2017 15:09:11 +0200 Message-ID: <1491224951-22437-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-03_09:, , signatures=0 X-Mailman-Approved-At: Tue, 04 Apr 2017 13:27:36 +0000 Cc: jean-philippe.romain@st.com Subject: [U-Boot] [PATCH RESEND v6] 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 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); }