linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: yang.yang29@zte.com.cn
Cc: steve.wahl@hpe.com, mike.travis@hpe.com,
	dimitri.sivanich@hpe.com, russ.anderson@hpe.com,
	dvhart@infradead.org, andy@infradead.org, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	x86@kernel.org, hpa@zytor.com,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, xu.panda@zte.com.cn
Subject: Re: [PATCH linux-next] x86/platform/uv: use strscpy to instead of strncpy()
Date: Sat, 3 Dec 2022 14:19:01 +0200	[thread overview]
Message-ID: <CAHp75VdRs5jwY749bMME1ciPFyETv5C8L-ECqoJPer3QeP+5jA@mail.gmail.com> (raw)
In-Reply-To: <CAHp75Vch84NZhZa_Gy4qNO1-6ZJq3GBGmJXHSDurW5jeoYzhdQ@mail.gmail.com>

On Sat, Dec 3, 2022 at 2:15 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Sat, Dec 3, 2022 at 8:24 AM <yang.yang29@zte.com.cn> wrote:

...

> >         /* (remove possible '\n') */
> > -       strncpy(arg, val, ACTION_LEN - 1);
> > -       arg[ACTION_LEN - 1] = '\0';
> > +       strscpy(arg, val, ACTION_LEN - 1);
>
> Should be ACTION_LEN here, no?
>
> >         p = strchr(arg, '\n');
> >         if (p)
> >                 *p = '\0';
>
> Wouldn't be better to refactor this
>
> p = strnchrnul(val, ACTION_LEN, '\n');
> strscpy(arg, val, p - val);

Or even drop p completely

strscpy(arg, val, strnchrnul(val, ACTION_LEN, '\n') - val);

-- 
With Best Regards,
Andy Shevchenko

      reply	other threads:[~2022-12-03 12:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-03  6:24 [PATCH linux-next] x86/platform/uv: use strscpy to instead of strncpy() yang.yang29
2022-12-03 12:15 ` Andy Shevchenko
2022-12-03 12:19   ` Andy Shevchenko [this message]

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=CAHp75VdRs5jwY749bMME1ciPFyETv5C8L-ECqoJPer3QeP+5jA@mail.gmail.com \
    --to=andy.shevchenko@gmail.com \
    --cc=andy@infradead.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dimitri.sivanich@hpe.com \
    --cc=dvhart@infradead.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.travis@hpe.com \
    --cc=mingo@redhat.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=russ.anderson@hpe.com \
    --cc=steve.wahl@hpe.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xu.panda@zte.com.cn \
    --cc=yang.yang29@zte.com.cn \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).