bcache: Use scnprintf() for avoiding potential buffer overflow
authorTakashi Iwai <tiwai@suse.de>
Sun, 22 Mar 2020 06:03:03 +0000 (14:03 +0800)
committerJens Axboe <axboe@kernel.dk>
Sun, 22 Mar 2020 16:06:57 +0000 (10:06 -0600)
Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/sysfs.c

index 3470fae4eabc1bfd268064d4902ac5e4ee4f13ed..323276994aab728894258f1ececed30bd85a33a3 100644 (file)
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
        size_t i;
 
        for (i = 0; list[i]; i++)
-               out += snprintf(out, buf + size - out,
+               out += scnprintf(out, buf + size - out,
                                i == selected ? "[%s] " : "%s ", list[i]);
 
        out[-1] = '\n';