[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VeieNZ3+-2oq2yx36mJ0ERBkuF=f_uhAh8o0sFnHY6Wsg@mail.gmail.com>
Date: Wed, 23 Aug 2023 14:07:07 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Justin Stitt <justinstitt@...gle.com>
Cc: Steve Wahl <steve.wahl@....com>, Mike Travis <mike.travis@....com>,
Dimitri Sivanich <dimitri.sivanich@....com>,
Russ Anderson <russ.anderson@....com>,
Darren Hart <dvhart@...radead.org>,
Andy Shevchenko <andy@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>,
platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] x86/platform/uv: refactor deprecated strcpy and strncpy
On Wed, Aug 23, 2023 at 1:32 AM Justin Stitt <justinstitt@...gle.com> wrote:
>
> Both `strncpy` and `strcpy` are deprecated for use on NUL-terminated
> destination strings [1].
>
> A suitable replacement is `strscpy` [2] due to the fact that it
> guarantees NUL-termination on its destination buffer argument which is
> _not_ the case for `strncpy` or `strcpy`!
>
> In this case, we can drop both the forced NUL-termination and the `... -1` from:
> | strncpy(arg, val, ACTION_LEN - 1);
> as `strscpy` implicitly has this behavior.
...
> char arg[ACTION_LEN], *p;
>
> /* (remove possible '\n') */
> - strncpy(arg, val, ACTION_LEN - 1);
> - arg[ACTION_LEN - 1] = '\0';
> + strscpy(arg, val, ACTION_LEN);
> p = strchr(arg, '\n');
> if (p)
> *p = '\0';
https://lore.kernel.org/all/202212091545310085328@zte.com.cn/
...
> + strscpy(uv_nmi_action, arg, strlen(uv_nmi_action));
strlen() on the destination?!
...
> - strncpy(uv_nmi_action, "dump", strlen(uv_nmi_action));
> + strscpy(uv_nmi_action, "dump", strlen(uv_nmi_action));
Again, this is weird.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists