diff mbox series

[-next] ACPICA: Replace strncpy() with strscpy_pad() for dest

Message ID 20231215072405.65887-1-luoxueqin@kylinos.cn (mailing list archive)
State Not Applicable, archived
Headers show
Series [-next] ACPICA: Replace strncpy() with strscpy_pad() for dest | expand

Commit Message

Xueqin Luo Dec. 15, 2023, 7:24 a.m. UTC
While it is safe to use strncpy in this case, the advice is to move to
strscpy_pad[1].

Link: https://www.kernel.org/doc/html/latest/process/deprec:qated.html#strncpy-on-nul-terminated-strings [1]
Signed-off-by: xueqin Luo <luoxueqin@kylinos.cn>
---
 drivers/acpi/acpica/utnonansi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Rafael J. Wysocki Dec. 21, 2023, 2:17 p.m. UTC | #1
On Fri, Dec 15, 2023 at 8:24 AM xueqin Luo <luoxueqin@kylinos.cn> wrote:
>
> While it is safe to use strncpy in this case, the advice is to move to
> strscpy_pad[1].
>
> Link: https://www.kernel.org/doc/html/latest/process/deprec:qated.html#strncpy-on-nul-terminated-strings [1]
> Signed-off-by: xueqin Luo <luoxueqin@kylinos.cn>
> ---
>  drivers/acpi/acpica/utnonansi.c | 3 +--

ACPICA code comes from an external project.  The proper way of
modifying it is to submit a pull request to the upstream ACPICA
project on GitHub.  Once this pull request has been merged upstream, a
Linux patch containing a Link: tag to the corresponding upstream pull
request can be submitted.

Thanks!

>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
> index ff0802ace19b..3a7952be6545 100644
> --- a/drivers/acpi/acpica/utnonansi.c
> +++ b/drivers/acpi/acpica/utnonansi.c
> @@ -168,8 +168,7 @@ void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
>  {
>         /* Always terminate destination string */
>
> -       strncpy(dest, source, dest_size);
> -       dest[dest_size - 1] = 0;
> +       strscpy_pad(dest, source, dest_size);
>  }
>
>  #endif
> --
> 2.34.1
>
>
diff mbox series

Patch

diff --git a/drivers/acpi/acpica/utnonansi.c b/drivers/acpi/acpica/utnonansi.c
index ff0802ace19b..3a7952be6545 100644
--- a/drivers/acpi/acpica/utnonansi.c
+++ b/drivers/acpi/acpica/utnonansi.c
@@ -168,8 +168,7 @@  void acpi_ut_safe_strncpy(char *dest, char *source, acpi_size dest_size)
 {
 	/* Always terminate destination string */
 
-	strncpy(dest, source, dest_size);
-	dest[dest_size - 1] = 0;
+	strscpy_pad(dest, source, dest_size);
 }
 
 #endif