Skip to content

Commit c1a3718

Browse files
lag-linarogregkh
authored andcommitted
usb: gadget: f_uac1: 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: Ruslan Bilovol <[email protected]> Cc: Julian Scheel <[email protected]> Cc: Bryan Wu <[email protected]> Signed-off-by: Lee Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0466e7e commit c1a3718

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/gadget/function/f_uac1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \
16341634
int result; \
16351635
\
16361636
mutex_lock(&opts->lock); \
1637-
result = snprintf(page, sizeof(opts->name), "%s", opts->name); \
1637+
result = scnprintf(page, sizeof(opts->name), "%s", opts->name); \
16381638
mutex_unlock(&opts->lock); \
16391639
\
16401640
return result; \
@@ -1652,7 +1652,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \
16521652
goto end; \
16531653
} \
16541654
\
1655-
ret = snprintf(opts->name, min(sizeof(opts->name), len), \
1655+
ret = scnprintf(opts->name, min(sizeof(opts->name), len), \
16561656
"%s", page); \
16571657
\
16581658
end: \
@@ -1758,7 +1758,7 @@ static struct usb_function_instance *f_audio_alloc_inst(void)
17581758

17591759
opts->req_number = UAC1_DEF_REQ_NUM;
17601760

1761-
snprintf(opts->function_name, sizeof(opts->function_name), "AC Interface");
1761+
scnprintf(opts->function_name, sizeof(opts->function_name), "AC Interface");
17621762

17631763
return &opts->func_inst;
17641764
}

0 commit comments

Comments
 (0)