Commit 234ff542 authored by Takashi Iwai's avatar Takashi Iwai Committed by Greg Kroah-Hartman

staging: most: core: Use scnprintf() for avoiding potential buffer overflow

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: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20200311091944.23185-1-tiwai@suse.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1693a2fa
...@@ -472,7 +472,7 @@ static int print_links(struct device *dev, void *data) ...@@ -472,7 +472,7 @@ static int print_links(struct device *dev, void *data)
list_for_each_entry(c, &iface->p->channel_list, list) { list_for_each_entry(c, &iface->p->channel_list, list) {
if (c->pipe0.comp) { if (c->pipe0.comp) {
offs += snprintf(buf + offs, offs += scnprintf(buf + offs,
PAGE_SIZE - offs, PAGE_SIZE - offs,
"%s:%s:%s\n", "%s:%s:%s\n",
c->pipe0.comp->name, c->pipe0.comp->name,
...@@ -480,7 +480,7 @@ static int print_links(struct device *dev, void *data) ...@@ -480,7 +480,7 @@ static int print_links(struct device *dev, void *data)
dev_name(&c->dev)); dev_name(&c->dev));
} }
if (c->pipe1.comp) { if (c->pipe1.comp) {
offs += snprintf(buf + offs, offs += scnprintf(buf + offs,
PAGE_SIZE - offs, PAGE_SIZE - offs,
"%s:%s:%s\n", "%s:%s:%s\n",
c->pipe1.comp->name, c->pipe1.comp->name,
...@@ -519,7 +519,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf) ...@@ -519,7 +519,7 @@ static ssize_t components_show(struct device_driver *drv, char *buf)
int offs = 0; int offs = 0;
list_for_each_entry(comp, &comp_list, list) { list_for_each_entry(comp, &comp_list, list) {
offs += snprintf(buf + offs, PAGE_SIZE - offs, "%s\n", offs += scnprintf(buf + offs, PAGE_SIZE - offs, "%s\n",
comp->name); comp->name);
} }
return offs; return offs;
......
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