Skip to content

Commit

Permalink
pinctrl: mediatek: Use scnprintf() for avoiding potential buffer over…
Browse files Browse the repository at this point in the history
…flow

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/20200311090644.20287-1-tiwai@suse.de
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Takashi Iwai authored and Linus Walleij committed Mar 27, 2020
1 parent 492464c commit 7eb42f9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/pinctrl/mediatek/pinctrl-paris.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
} else if (pullen != MTK_DISABLE && pullen != MTK_ENABLE) {
pullen = 0;
}
len += snprintf(buf + len, bufLen - len,
len += scnprintf(buf + len, bufLen - len,
"%03d: %1d%1d%1d%1d%02d%1d%1d%1d%1d",
gpio,
pinmux,
Expand All @@ -625,10 +625,10 @@ ssize_t mtk_pctrl_show_one_pin(struct mtk_pinctrl *hw,
pullup);

if (r1 != -1) {
len += snprintf(buf + len, bufLen - len, " (%1d %1d)\n",
len += scnprintf(buf + len, bufLen - len, " (%1d %1d)\n",
r1, r0);
} else {
len += snprintf(buf + len, bufLen - len, "\n");
len += scnprintf(buf + len, bufLen - len, "\n");
}

return len;
Expand Down

0 comments on commit 7eb42f9

Please sign in to comment.