All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar
@ 2017-04-03  9:28 Nicolas le bayon
  2017-04-03  9:50 ` Lukasz Majewski
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas le bayon @ 2017-04-03  9:28 UTC (permalink / raw)
  To: u-boot

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>
Reviewed-by: Marek Vasut <marex@denx.de>
---

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);
 }
--
1.9.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar
  2017-04-03  9:28 [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar Nicolas le bayon
@ 2017-04-03  9:50 ` Lukasz Majewski
  2017-04-03 11:34   ` Marek Vasut
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Majewski @ 2017-04-03  9:50 UTC (permalink / raw)
  To: u-boot

On Mon, 3 Apr 2017 11:28:44 +0200
Nicolas le bayon <nlebayon@gmail.com> wrote:

> 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.

Acked-by: Lukasz Majewski <lukma@denx.de>

> 
> Signed-off-by: Nicolas Le Bayon <nlebayon@gmail.com>
> Reviewed-by: Marek Vasut <marex@denx.de>

Marek, could you pull this patch directly to -usb tree? I do not have
more -dfu patches to pull to this merge window. Thanks in advance.


> ---
> 
> 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);
>  }
> --
> 1.9.1




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar
  2017-04-03  9:50 ` Lukasz Majewski
@ 2017-04-03 11:34   ` Marek Vasut
  2017-04-03 12:26     ` Nicolas le bayon
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Vasut @ 2017-04-03 11:34 UTC (permalink / raw)
  To: u-boot

On 04/03/2017 11:50 AM, Lukasz Majewski wrote:
> On Mon, 3 Apr 2017 11:28:44 +0200
> Nicolas le bayon <nlebayon@gmail.com> wrote:
> 
>> 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.
> 
> Acked-by: Lukasz Majewski <lukma@denx.de>
> 
>>
>> Signed-off-by: Nicolas Le Bayon <nlebayon@gmail.com>
>> Reviewed-by: Marek Vasut <marex@denx.de>
> 
> Marek, could you pull this patch directly to -usb tree? I do not have
> more -dfu patches to pull to this merge window. Thanks in advance.

I cannot seem to be able to apply the patch, either from my mailer or
patchwork. Was it sent with git send-email or something else ? The
formatting of the patch seems to be screwed up.

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar
  2017-04-03 11:34   ` Marek Vasut
@ 2017-04-03 12:26     ` Nicolas le bayon
  2017-04-03 12:32       ` Marek Vasut
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas le bayon @ 2017-04-03 12:26 UTC (permalink / raw)
  To: u-boot

2017-04-03 13:34 GMT+02:00 Marek Vasut <marex@denx.de>:

> On 04/03/2017 11:50 AM, Lukasz Majewski wrote:
> > On Mon, 3 Apr 2017 11:28:44 +0200
> > Nicolas le bayon <nlebayon@gmail.com> wrote:
> >
> >> 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.
> >
> > Acked-by: Lukasz Majewski <lukma@denx.de>
> >
> >>
> >> Signed-off-by: Nicolas Le Bayon <nlebayon@gmail.com>
> >> Reviewed-by: Marek Vasut <marex@denx.de>
> >
> > Marek, could you pull this patch directly to -usb tree? I do not have
> > more -dfu patches to pull to this merge window. Thanks in advance.
>
> I cannot seem to be able to apply the patch, either from my mailer or
> patchwork. Was it sent with git send-email or something else ? The
> formatting of the patch seems to be screwed up.
>

You're right Marek, I saw its patchwork and it's corrupted.
It was well-sent by git send-email but I made a mistake in the addition of
the changelog.

I'm going to do a RESEND with the ack of Lukasz and the correct format.

Sorry for that
Nicolas

>
> --
> Best regards,
> Marek Vasut
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar
  2017-04-03 12:26     ` Nicolas le bayon
@ 2017-04-03 12:32       ` Marek Vasut
  0 siblings, 0 replies; 5+ messages in thread
From: Marek Vasut @ 2017-04-03 12:32 UTC (permalink / raw)
  To: u-boot

On 04/03/2017 02:26 PM, Nicolas le bayon wrote:
> 2017-04-03 13:34 GMT+02:00 Marek Vasut <marex@denx.de>:
> 
>> On 04/03/2017 11:50 AM, Lukasz Majewski wrote:
>>> On Mon, 3 Apr 2017 11:28:44 +0200
>>> Nicolas le bayon <nlebayon@gmail.com> wrote:
>>>
>>>> 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.
>>>
>>> Acked-by: Lukasz Majewski <lukma@denx.de>
>>>
>>>>
>>>> Signed-off-by: Nicolas Le Bayon <nlebayon@gmail.com>
>>>> Reviewed-by: Marek Vasut <marex@denx.de>
>>>
>>> Marek, could you pull this patch directly to -usb tree? I do not have
>>> more -dfu patches to pull to this merge window. Thanks in advance.
>>
>> I cannot seem to be able to apply the patch, either from my mailer or
>> patchwork. Was it sent with git send-email or something else ? The
>> formatting of the patch seems to be screwed up.
>>
> 
> You're right Marek, I saw its patchwork and it's corrupted.
> It was well-sent by git send-email but I made a mistake in the addition of
> the changelog.
> 
> I'm going to do a RESEND with the ack of Lukasz and the correct format.
> 
OK


-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-03 12:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03  9:28 [U-Boot] [PATCH v6 1/1] usb: gadget: avoid variable name clipping in cb_getvar Nicolas le bayon
2017-04-03  9:50 ` Lukasz Majewski
2017-04-03 11:34   ` Marek Vasut
2017-04-03 12:26     ` Nicolas le bayon
2017-04-03 12:32       ` Marek Vasut

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.