public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] auxdisplay: use correct string length
@ 2018-01-16  9:38 Xiongfeng Wang
  2018-02-12 12:53 ` Miguel Ojeda
  0 siblings, 1 reply; 7+ messages in thread
From: Xiongfeng Wang @ 2018-01-16  9:38 UTC (permalink / raw)
  To: dan.carpenter; +Cc: miguel.ojeda.sandonis, arnd, linux-kernel, wangxiongfeng2

From: Xiongfeng Wang <xiongfeng.wang@linaro.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@linaro.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);
 	list_add(&key->list, &logical_inputs);
 	return key;
 }
-- 
1.8.3.1

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

end of thread, other threads:[~2018-02-13  8:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-16  9:38 [PATCH V2] auxdisplay: use correct string length Xiongfeng Wang
2018-02-12 12:53 ` Miguel Ojeda
2018-02-12 17:11   ` Willy Tarreau
2018-02-12 20:42     ` Miguel Ojeda
2018-02-13  1:19   ` Xiongfeng Wang
2018-02-13  7:23     ` Willy Tarreau
2018-02-13  8:28       ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox