linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow
@ 2020-03-11  9:06 Takashi Iwai
  2020-03-19 15:53 ` Takashi Iwai
  2020-03-27 10:31 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Takashi Iwai @ 2020-03-11  9:06 UTC (permalink / raw)
  To: Sean Wang, Linus Walleij, Matthias Brugger; +Cc: linux-mediatek, linux-gpio

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>
---
 drivers/pinctrl/mediatek/pinctrl-paris.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
index 3ee8086f5e55..3853ec3a2a8e 100644
--- a/drivers/pinctrl/mediatek/pinctrl-paris.c
+++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
@@ -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,
@@ -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;
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow
  2020-03-11  9:06 [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
@ 2020-03-19 15:53 ` Takashi Iwai
  2020-03-27 10:31 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2020-03-19 15:53 UTC (permalink / raw)
  To: Sean Wang, Linus Walleij, Matthias Brugger; +Cc: linux-mediatek, linux-gpio

On Wed, 11 Mar 2020 10:06:44 +0100,
Takashi Iwai wrote:
> 
> 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>

A gentle reminder for this forgotten patch.
Let me know if any further change is needed.


thanks,

Takashi

> ---
>  drivers/pinctrl/mediatek/pinctrl-paris.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pinctrl/mediatek/pinctrl-paris.c b/drivers/pinctrl/mediatek/pinctrl-paris.c
> index 3ee8086f5e55..3853ec3a2a8e 100644
> --- a/drivers/pinctrl/mediatek/pinctrl-paris.c
> +++ b/drivers/pinctrl/mediatek/pinctrl-paris.c
> @@ -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,
> @@ -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;
> -- 
> 2.16.4
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow
  2020-03-11  9:06 [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
  2020-03-19 15:53 ` Takashi Iwai
@ 2020-03-27 10:31 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2020-03-27 10:31 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Sean Wang, Matthias Brugger,
	moderated list:ARM/Mediatek SoC support,
	open list:GPIO SUBSYSTEM

On Wed, Mar 11, 2020 at 10:06 AM Takashi Iwai <tiwai@suse.de> wrote:

> 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>

No reaction from maintainers so patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-27 10:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  9:06 [PATCH] pinctrl: mediatek: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
2020-03-19 15:53 ` Takashi Iwai
2020-03-27 10:31 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).