Skip to content

Commit d32dcb0

Browse files
lag-linarogregkh
authored andcommitted
usb: gadget: udc: atmel: 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: Cristian Birsan <[email protected]> Cc: Nicolas Ferre <[email protected]> Cc: Alexandre Belloni <[email protected]> Cc: Claudiu Beznea <[email protected]> Cc: <[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 0d12c1c commit d32dcb0

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/usb/gadget/udc/atmel_usba_udc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static ssize_t queue_dbg_read(struct file *file, char __user *buf,
9494

9595
inode_lock(file_inode(file));
9696
list_for_each_entry_safe(req, tmp_req, queue, queue) {
97-
len = snprintf(tmpbuf, sizeof(tmpbuf),
97+
len = scnprintf(tmpbuf, sizeof(tmpbuf),
9898
"%8p %08x %c%c%c %5d %c%c%c\n",
9999
req->req.buf, req->req.length,
100100
req->req.no_interrupt ? 'i' : 'I',
@@ -104,7 +104,6 @@ static ssize_t queue_dbg_read(struct file *file, char __user *buf,
104104
req->submitted ? 'F' : 'f',
105105
req->using_dma ? 'D' : 'd',
106106
req->last_transaction ? 'L' : 'l');
107-
len = min(len, sizeof(tmpbuf));
108107
if (len > nbytes)
109108
break;
110109

0 commit comments

Comments
 (0)