summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[email protected] <[email protected]>2017-05-09 15:58:36 +0000
committerTom Rini <[email protected]>2017-05-11 22:03:36 -0400
commitb1f2a17c780ce9b1d7666bcc6eef82ce9bb4b27f (patch)
tree24330fb3a6495a1c57c01a241973310e3e014596
parent1f5541c8818d3ecd243f9bbf58db9ea5f55a3195 (diff)
usb: gadget: avoid variable name clipping in cb_getvar
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 <[email protected]>; [email protected]; [email protected]; [email protected] Cc: [email protected]; Patrice CHOTARD <[email protected]>; Jean-philippe ROMAIN <[email protected]> Subject: [U-Boot][PATCH v7] usb: gadget: avoid variable name clipping in cb_getvar From: Nicolas Le Bayon <[email protected]> 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 <[email protected]> Reviewed-by: Marek Vasut <[email protected]> Acked-by: Lukasz Majewski <[email protected]>
-rw-r--r--drivers/usb/gadget/f_fastboot.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index 2160b1ccdc3..7cd6d24bf50 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);
}