UPSTREAM: usb: gadget: uvc: fix changing interface name via configfs
When setting the function name, it is always truncated by one char since
snprintf is always including the null-termination in the len parameter.
We use strscpy and fix the size setting to use len + 1 instead.
Bug: 254441685
Fixes: 324e4f85070f ("usb: gadget: uvc: allow changing interface name via configfs")
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220707115612.2760569-1-m.grzeschik@pengutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 3d0dc539029b09fbd125444c16b11a8ed10b9d0f)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I474825f228513a11403605764def13f3a0fdb38c
This commit is contained in:
committed by
Treehugger Robot
parent
1b90823b62
commit
737bf2358f
@@ -2443,6 +2443,7 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
|
||||
const char *page, size_t len) \
|
||||
{ \
|
||||
struct f_uvc_opts *opts = to_f_uvc_opts(item); \
|
||||
int size = min(sizeof(opts->aname), len + 1); \
|
||||
int ret = 0; \
|
||||
\
|
||||
mutex_lock(&opts->lock); \
|
||||
@@ -2451,8 +2452,9 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
|
||||
goto end; \
|
||||
} \
|
||||
\
|
||||
ret = snprintf(opts->aname, min(sizeof(opts->aname), len), \
|
||||
"%s", page); \
|
||||
ret = strscpy(opts->aname, page, size); \
|
||||
if (ret == -E2BIG) \
|
||||
ret = size - 1; \
|
||||
\
|
||||
end: \
|
||||
mutex_unlock(&opts->lock); \
|
||||
|
||||
Reference in New Issue
Block a user