[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vc-gMuv=HpiF-LURrpy+0MDiQUe0hVv24pRezhQg2E-Lw@mail.gmail.com>
Date: Mon, 5 Dec 2022 15:13:24 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: yang.yang29@....com.cn
Cc: steve.wahl@....com, mike.travis@....com, dimitri.sivanich@....com,
russ.anderson@....com, dvhart@...radead.org, andy@...radead.org,
tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com,
platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
xu.panda@....com.cn
Subject: Re: [PATCH linux-next v2] x86/platform/uv: use strscpy to instead of strncpy()
On Mon, Dec 5, 2022 at 1:42 PM <yang.yang29@....com.cn> wrote:
>
> From: Xu Panda <xu.panda@....com.cn>
Thank you for an update, my comments below.
> The implementation of strscpy() is more robust and safer.
> That's now the recommended way to copy NUL terminated strings.
> ---
> change for v2
> - fix the mistake and make the code better and simpler,
> thanks to Andy Shevchenko.
> ---
This is (the changelog) in the wrong place.
> Signed-off-by: Xu Panda <xu.panda@....com.cn>
> Signed-off-by: Yang Yang <yang.yang29@....com>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@...il.com>
No, I haven't given you this tag, sorry. The changelog is enough to give credit.
...
> char arg[ACTION_LEN], *p;
>
> /* (remove possible '\n') */
> - strncpy(arg, val, ACTION_LEN - 1);
> - arg[ACTION_LEN - 1] = '\0';
> - p = strchr(arg, '\n');
> - if (p)
> - *p = '\0';
> + strscpy(arg, val, strnchrnul(val, ACTION_LEN, '\n') - val);
And even better is to replace ACTION_LEN by sizeof(arg).
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists