[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72=AeytaT5KBtujTBUkfbNTFFxMPAeToqzmZJOr790R6yw@mail.gmail.com>
Date: Mon, 12 Feb 2018 13:53:57 +0100
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Xiongfeng Wang <wangxiongfeng2@...wei.com>,
Willy Tarreau <w@....eu>
Cc: Dan <dan.carpenter@...cle.com>, Arnd Bergmann <arnd@...db.de>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH V2] auxdisplay: use correct string length
On Tue, Jan 16, 2018 at 10:38 AM, Xiongfeng Wang
<wangxiongfeng2@...wei.com> wrote:
> From: Xiongfeng Wang <xiongfeng.wang@...aro.org>
>
> gcc-8 reports
>
> drivers/auxdisplay/panel.c: In function 'panel_attach':
> ./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
> bound 12 equals destination size [-Wstringop-truncation]
>
> We need one less byte or call strlcpy() to make it a nul-terminated
> string.
>
> Signed-off-by: Xiongfeng Wang <xiongfeng.wang@...aro.org>
> ---
> drivers/auxdisplay/panel.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/auxdisplay/panel.c b/drivers/auxdisplay/panel.c
> index ea7869c..d288900 100644
> --- a/drivers/auxdisplay/panel.c
> +++ b/drivers/auxdisplay/panel.c
> @@ -1506,10 +1506,10 @@ static struct logical_input *panel_bind_key(const char *name, const char *press,
> key->rise_time = 1;
> key->fall_time = 1;
>
> - strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str));
> - strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str));
> + strncpy(key->u.kbd.press_str, press, sizeof(key->u.kbd.press_str) - 1);
> + strncpy(key->u.kbd.repeat_str, repeat, sizeof(key->u.kbd.repeat_str) - 1);
> strncpy(key->u.kbd.release_str, release,
> - sizeof(key->u.kbd.release_str));
> + sizeof(key->u.kbd.release_str) - 1);
Are you sure about this patch? `kbd` says "strings can be non null-terminated".
Willy, maybe those should just be memcpy()s? (unless the remaining
bytes, if any, must be 0).
Thanks,
Miguel
> list_add(&key->list, &logical_inputs);
> return key;
> }
> --
> 1.8.3.1
>
Powered by blists - more mailing lists