Skip to content

Commit 0d12c1c

Browse files
lag-linarogregkh
authored andcommitted
usb: gadget: uvc: Replace snprintf() with the safer scnprintf() variant
There is a general misunderstanding amongst engineers that {v}snprintf() returns the length of the data *actually* encoded into the destination array. However, as per the C99 standard {v}snprintf() really returns the length of the data that *would have been* written if there were enough space for it. This misunderstanding has led to buffer-overruns in the past. It's generally considered safer to use the {v}scnprintf() variants in their place (or even sprintf() in simple cases). So let's do that. Link: https://lwn.net/Articles/69419/ Link: KSPP/linux#105 Cc: Laurent Pinchart <[email protected]> Cc: Daniel Scally <[email protected]> Cc: Andrzej Pietrasiewicz <[email protected]> Signed-off-by: Lee Jones <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 60034e0 commit 0d12c1c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/usb/gadget/function/uvc_configfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3414,7 +3414,7 @@ static ssize_t f_uvc_opts_string_##cname##_show(struct config_item *item,\
34143414
int result; \
34153415
\
34163416
mutex_lock(&opts->lock); \
3417-
result = snprintf(page, sizeof(opts->aname), "%s", opts->aname);\
3417+
result = scnprintf(page, sizeof(opts->aname), "%s", opts->aname);\
34183418
mutex_unlock(&opts->lock); \
34193419
\
34203420
return result; \

0 commit comments

Comments
 (0)