Received: by 10.223.185.116 with SMTP id b49csp2886559wrg; Mon, 12 Feb 2018 17:20:32 -0800 (PST) X-Google-Smtp-Source: AH8x227huNVmWyYHS4To+ZgaeETQU5CmnS/Pj9B6eblsQKmTfN3q5hNpTVhzWhzbGd/aB+Gbqeal X-Received: by 10.101.80.69 with SMTP id k5mr10871279pgo.425.1518484832494; Mon, 12 Feb 2018 17:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518484832; cv=none; d=google.com; s=arc-20160816; b=fjlNpLPzoNp2Y/z4UON+px6qRrXKWfm+eWnGCp9a6XPmthAR6vT5z9Sk9AfhJIC6IE oOp/22ukcFFZUzcWiVOFDzDPH8Q5Ph0J2lQvpM5JPEk336izwais5f0jSbRQEwtriGhY gglCyVrT95HoiaDcIHfu+Y+WUQzxQUl0YxZ7sT2Xn++RB0D8sem3OoOO77rroB5hDJeN N8c23WnPSJETLilGFPuL6ILWIRBpLc7GpQeE4T9uA3oUKulYyGRa5hukxwh5DPPMzWL5 JsuTi+vJf5TLSUZPNqD9sNSC4rtJrnSkIlNZu2gBJhSGUHX5gU4ecEiFXfvM2XQTj6cm Cn7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=oaeWiUTcpUyluhftP0/2iZprufYQtYHyuF07RlC2/ss=; b=fyyp3t1uXDSAQ1jd1fGy0YaZ3KhSiB34UF11CoRULupLo1/wQsPx/zwW20kG5aPT7v p3NcfagC4tstUhqTR++iIPdXnS6SSc2Nfs9VCJvxGog8NKm27hhRxqp3MgcN1LV4OTjc ENe/IprEEpGDqt0KO1m6xo7ByvoJj42pxq9N+fPnllWxIWskn8snuaQEEAGm8p2fibKm kQsMnhkHdD9aMWOCwwM0AYMaByRMUaK2oQ2OAmVztC6bwxLbXcx8I87y4tO6KE1p2gVh nGCutP4LknspaeIAzifWxfdL1SJ2SQ/xbcu/3hrwD1mxsimNnYJwMlI45jQmPVBJUdUy Rmfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i64-v6si6672129pli.142.2018.02.12.17.20.16; Mon, 12 Feb 2018 17:20:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933080AbeBMBTj (ORCPT + 99 others); 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 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9B4047991FF98; Tue, 13 Feb 2018 09:19:24 +0800 (CST) Received: from [127.0.0.1] (10.177.32.209) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.361.1; Tue, 13 Feb 2018 09:19:21 +0800 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 Precedence: bulk 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 >> > > . >