]> git.baikalelectronics.ru Git - kernel.git/commit
iio: tsl2772: Use scnprintf() for avoiding potential buffer overflow
authorTakashi Iwai <tiwai@suse.de>
Mon, 16 Mar 2020 12:49:41 +0000 (13:49 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 19 Apr 2020 15:56:14 +0000 (16:56 +0100)
commit47776ee2b9bb931692d4ea7d095f6121d16dbf48
treef6b9591adf18a220def9e51688a4a3b24c773d3f
parent90e342c2d03ac4b9853e15e11628a732319a6eb7
iio: tsl2772: Use scnprintf() for avoiding potential buffer overflow

snprintf() is a hard-to-use function, it's especially difficult to use
it for concatenating substrings in a buffer with a limited size.
Since snprintf() returns the would-be-output size, not the actual
size, the subsequent use of snprintf() may go beyond the given limit
easily.  Although the current code doesn't actually overflow the
buffer, it's an incorrect usage.

This patch replaces such snprintf() calls with a safer version,
scnprintf().

Also this fixes the incorrect argument of the buffer limit size passed
to snprintf(), too.  The size has to be decremented for the remaining
length.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/tsl2772.c