Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3479381pxt; Tue, 10 Aug 2021 04:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz3JYgx3rju9i+QeDlX7xCMN+IUKDDaiHNt+Svydrx67UT3XhtPUfcC28hGcYUNypxkSwA X-Received: by 2002:a92:ddc9:: with SMTP id d9mr331523ilr.204.1628596138678; Tue, 10 Aug 2021 04:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628596138; cv=none; d=google.com; s=arc-20160816; b=qKrAt1KubHHTOukKRv6oA4ztFmlDtPe/a3geVzPhb1iXsOp75JZbAf70BzWqRHSZuB w6zyzl6AnZzyUkzvwq3iM5eMRiMSSEmXLapP9NIN4FlFc1O848AFylb/9z7uFTc8gTFU g+FZRYLGyofZIEusDk9xNNTX0q8+b6pHYz/NYsn2xYq/IzP1FibIMzdO/wXQK8GZaA2z goKXy9ehODHxpO+eUcBtpPcNurQ7js0mgQppGiL9tnVTkjpKqCz9fuulSHlhF+KTSaEc CHaOGKz1kBHqKCPdHzGIvFjl80DRWyvBDssPJwAotUOti3caA76l5Hq7yLDyAblRRW9O Qajg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=QqDCBO7BBv17sB2h8iCgB70lxpxyuetehUQrq1JDixQ=; b=Zy+T3Pt1vpEzcZWpv0eLVFWZN3pnIYAd0CcNYVy38CU4o2HUFdDfhLs8z4DrUXagcd Nbr3dNb2c/uZnk5snHZdl9anQwRm3JUy45f6jnPaRBQ46mLrw3lwWn1zKgSFoySpG00V mn0FxQ4+nJtIGTDjcLEsgGOdDr9D4kRlYu4gEk/cTSFevGLc51ubeqVrzUzfHtTSe3YR fkU/MENloFYhSWJgq+Xxue10LL8p9xM1IzJWrozWrWY+9Ut7setFMD8cuCt/mtnGSeOq ETsbgvPlPzqCh3aX1dJynfP672MhsfVwmin8WArZzkTfgyQTryW1oowd9/RMvsnlYNcn B95Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w12si8224383jal.15.2021.08.10.04.48.42; Tue, 10 Aug 2021 04:48:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238348AbhHJI5S convert rfc822-to-8bit (ORCPT + 99 others); Tue, 10 Aug 2021 04:57:18 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.85.151]:20136 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238335AbhHJI5Q (ORCPT ); Tue, 10 Aug 2021 04:57:16 -0400 Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-234-w1_GZZkGMW-hVo-Y0c_N0g-1; Tue, 10 Aug 2021 09:56:52 +0100 X-MC-Unique: w1_GZZkGMW-hVo-Y0c_N0g-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 10 Aug 2021 09:56:52 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.023; Tue, 10 Aug 2021 09:56:52 +0100 From: David Laight To: 'Joe Perches' , Robert Richter , "Len Baker" CC: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck , James Morse , Kees Cook , "linux-hardening@vger.kernel.org" , "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v3] drivers/edac/edac_mc: Remove all strcpy() uses Thread-Topic: [PATCH v3] drivers/edac/edac_mc: Remove all strcpy() uses Thread-Index: AQHXjUKovGKiu304s0CSrAMXVBAc3KtsbpXQ Date: Tue, 10 Aug 2021 08:56:51 +0000 Message-ID: References: <20210807155957.10069-1-len.baker@gmx.com> <20210808112617.GA1927@titan> <99448ef29830fda9b19409bc23b0e7513b22f7b7.camel@perches.com> In-Reply-To: <99448ef29830fda9b19409bc23b0e7513b22f7b7.camel@perches.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joe Perches > Sent: 09 August 2021 18:19 > > On Mon, 2021-08-09 at 12:05 +0200, Robert Richter wrote: > > On 08.08.21 13:26:17, Len Baker wrote: > > > > > > Perhaps this should use scnprintf rather than strscpy > > > > Something like: > > > > n += scnprintf(buf + n, len - n, "%s", > > > > p == e->label ? dim->label : OTHER_LABEL); > > > > > > > In the first version [1] the scnprintf was used but Robert Richter don't > > > see any benefit compared with the current implementation. > > > > > > [1] https://lore.kernel.org/linux-hardening/20210725162954.9861-1-len.baker@gmx.com/ > > > > Reason is that there is the assumption that p must always point at the > > end of the string and its trailing zero byte. I am not opposed using > > the string function's return code instead of strlen() to get the > > length. But why using formated output if strscpy() can be used? > > strscpy and scnprintf have different return values and it's simpler > and much more common to use scnprintf for appended strings that are > limited to a specific buffer length. scnprintf() will be a lot slower, but has a much better return value than most of the strxxxcpy() functions. The only slight problem is that you can't differentiate overflow from a max-length output. Trouble is fixing that adds 'yet another set of functions'. Clearly we need the yellow with purple stripe ones :-) Probably: offset = xxx(buf, len, offset, ......) where offset == len on truncation. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)