linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Richter <rric@kernel.org>
To: Joe Perches <joe@perches.com>
Cc: Len Baker <len.baker@gmx.com>, Borislav Petkov <bp@alien8.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Tony Luck <tony.luck@intel.com>,
	James Morse <james.morse@arm.com>,
	Kees Cook <keescook@chromium.org>,
	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
Date: Wed, 11 Aug 2021 09:40:34 +0200	[thread overview]
Message-ID: <YRN+8u59lJ6MWsOL@rric.localdomain> (raw)
In-Reply-To: <b3070c0352e2a5661a1a59d5c5354cc82a1cce1e.camel@perches.com>

On 10.08.21 08:02:17, Joe Perches wrote:
> On Tue, 2021-08-10 at 16:36 +0200, Robert Richter wrote:
> > On 09.08.21 10:18:58, Joe Perches wrote:
> > 
> > > 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.
> > 
> > Calculating the bytes written from the return value is a oneliner.
> 
> Not really.
> You still have to test for strscpy's possible return of -E2BIG.

I thought of:

	num = strscpy(p, OTHER_LABEL, len);
	num = num < 0 ? len : num;
	len -= num;
	p += num;

Clearly, this does not look nice, esp. if this is repeated in the
code. That's why I prefer the strlen(p) implementation:

	strscpy(p, OTHER_LABEL, len);
	len -= strlen(p);
	p += strlen(p);

-Robert

  reply	other threads:[~2021-08-11  7:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-07 15:59 Len Baker
2021-08-07 17:09 ` Joe Perches
2021-08-08 11:26   ` Len Baker
2021-08-09 10:05     ` Robert Richter
2021-08-09 17:18       ` Joe Perches
2021-08-10  8:56         ` David Laight
2021-08-10 14:36         ` Robert Richter
2021-08-10 15:02           ` Joe Perches
2021-08-11  7:40             ` Robert Richter [this message]
2021-08-09  9:51 ` Robert Richter
2021-08-09 16:25   ` Len Baker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YRN+8u59lJ6MWsOL@rric.localdomain \
    --to=rric@kernel.org \
    --cc=bp@alien8.de \
    --cc=james.morse@arm.com \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=len.baker@gmx.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=tony.luck@intel.com \
    --subject='Re: [PATCH v3] drivers/edac/edac_mc: Remove all strcpy() uses' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).