Commit 3d0dc539 authored by Michael Grzeschik's avatar Michael Grzeschik Committed by Greg Kroah-Hartman
Browse files

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.

Fixes: 324e4f85 ("usb: gadget: uvc: allow changing interface name via configfs")
Signed-off-by: default avatarMichael Grzeschik <m.grzeschik@pengutronix.de>
Link: https://lore.kernel.org/r/20220707115612.2760569-1-m.grzeschik@pengutronix.de


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6fb9e1d9
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2371,6 +2371,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);					\
@@ -2379,8 +2380,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);					\