From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933090AbeBMBTj (ORCPT ); Mon, 12 Feb 2018 20:19:39 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:56469 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932736AbeBMBTh (ORCPT ); Mon, 12 Feb 2018 20:19:37 -0500 Subject: Re: [PATCH V2] auxdisplay: use correct string length To: Miguel Ojeda , Willy Tarreau References: <1516095490-83827-1-git-send-email-wangxiongfeng2@huawei.com> CC: Dan , Arnd Bergmann , linux-kernel From: Xiongfeng Wang Message-ID: Date: Tue, 13 Feb 2018 09:19:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.32.209] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/2/12 20:53, Miguel Ojeda wrote: > On Tue, Jan 16, 2018 at 10:38 AM, Xiongfeng Wang > wrote: >> From: Xiongfeng Wang >> >> 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 >> --- >> 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). Sorry, my apologies. I think I made a mistake. I meant to use strlcpy(), but this also decrease the destination storage size by one. I think, if the strings can be non null-terminated, we can just use memcpy(). This may suppress the gcc warning. Thanks, Xiongfeng > > Thanks, > Miguel > >> list_add(&key->list, &logical_inputs); >> return key; >> } >> -- >> 1.8.3.1 >> > > . >