All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas le bayon <nlebayon@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 1/1] usb: gadget: avoid variable name clipping in cb_getvar
Date: Fri, 17 Mar 2017 10:57:25 +0100	[thread overview]
Message-ID: <CAJZhe_jYH+1215ufzYL+EwOQ50DKorZ1UYCAofF26hSKmHeW-Q@mail.gmail.com> (raw)

From: Nicolas Le Bayon <nlebayon@gmail.com>

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 <nlebayon@gmail.com>
---
 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);
 }
--
1.9.1

             reply	other threads:[~2017-03-17  9:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-17  9:57 Nicolas le bayon [this message]
2017-03-17 12:26 ` [U-Boot] [PATCH v5 1/1] usb: gadget: avoid variable name clipping in cb_getvar Marek Vasut
2017-03-21  8:53   ` Nicolas le bayon
2017-03-28  9:10     ` Nicolas le bayon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJZhe_jYH+1215ufzYL+EwOQ50DKorZ1UYCAofF26hSKmHeW-Q@mail.gmail.com \
    --to=nlebayon@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.