Skip to content

Commit

Permalink
misc: mic: Use scnprintf() for avoiding potential buffer overflow
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/20200311074916.8783-1-tiwai@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Takashi Iwai authored and Greg Kroah-Hartman committed Mar 18, 2020
1 parent f276d3e commit d108b13
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/misc/mic/host/mic_x100.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ mic_x100_load_command_line(struct mic_device *mdev, const struct firmware *fw)
if (!buf)
return -ENOMEM;

len += snprintf(buf, CMDLINE_SIZE - len,
len += scnprintf(buf, CMDLINE_SIZE - len,
" mem=%dM", boot_mem);
if (mdev->cosm_dev->cmdline)
snprintf(buf + len, CMDLINE_SIZE - len, " %s",
scnprintf(buf + len, CMDLINE_SIZE - len, " %s",
mdev->cosm_dev->cmdline);
memcpy_toio(cmd_line_va, buf, strlen(buf) + 1);
kfree(buf);
Expand Down

0 comments on commit d108b13

Please sign in to comment.