]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ASoC: Intel: avs: Fix potential buffer overflow by snprintf()
authorTakashi Iwai <tiwai@suse.de>
Mon, 1 Aug 2022 16:54:18 +0000 (18:54 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 5 Aug 2022 11:57:22 +0000 (12:57 +0100)
snprintf() returns the would-be-filled size when the string overflows
the given buffer size, hence using this value may result in a buffer
overflow (although it's unrealistic).

This patch replaces it with a safer version, scnprintf() for papering
over such a potential issue.

Fixes: f3d19cfc6230 ("ASoC: Intel: avs: Generic soc component driver")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://lore.kernel.org/r/20220801165420.25978-2-tiwai@suse.de
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/avs/pcm.c

index f21b0cdd320630cfca48253574e701470a1b8919..8fe5917b1e2637ece466f89cc5d9e7da123f8039 100644 (file)
@@ -636,8 +636,8 @@ static ssize_t topology_name_read(struct file *file, char __user *user_buf, size
        char buf[64];
        size_t len;
 
-       len = snprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix,
-                      mach->tplg_filename);
+       len = scnprintf(buf, sizeof(buf), "%s/%s\n", component->driver->topology_name_prefix,
+                       mach->tplg_filename);
 
        return simple_read_from_buffer(user_buf, count, ppos, buf, len);
 }