Commit 1eb123ce authored by Takashi Iwai's avatar Takashi Iwai Committed by Mark Brown

ASoC: SOF: debug: Fix potential buffer overflow by snprintf()

snprintf() returns the would-be-filled size when the string overflows
the given buffer size, hence using this value may result in the buffer
overflow (although it's unrealistic).

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

Fixes: 5b10b629 ("ASoC: SOF: Add `memory_info` file to debugfs")
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20220801165420.25978-3-tiwai@suse.deSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent ca3b7b9d
...@@ -252,9 +252,9 @@ static int memory_info_update(struct snd_sof_dev *sdev, char *buf, size_t buff_s ...@@ -252,9 +252,9 @@ static int memory_info_update(struct snd_sof_dev *sdev, char *buf, size_t buff_s
} }
for (i = 0, len = 0; i < reply->num_elems; i++) { for (i = 0, len = 0; i < reply->num_elems; i++) {
ret = snprintf(buf + len, buff_size - len, "zone %d.%d used %#8x free %#8x\n", ret = scnprintf(buf + len, buff_size - len, "zone %d.%d used %#8x free %#8x\n",
reply->elems[i].zone, reply->elems[i].id, reply->elems[i].zone, reply->elems[i].id,
reply->elems[i].used, reply->elems[i].free); reply->elems[i].used, reply->elems[i].free);
if (ret < 0) if (ret < 0)
goto error; goto error;
len += ret; len += ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment