linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] ACPICA: Use strscpy to replace strncpy
@ 2023-08-31  7:34 Su Hui
  2023-08-31  9:35 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Su Hui @ 2023-08-31  7:34 UTC (permalink / raw)
  To: robert.moore, rafael.j.wysocki, lenb
  Cc: linux-acpi, acpica-devel, linux-kernel, kernel-janitors, Su Hui

With gcc and W=1 option to compile kernel, warning happens:

inlined from ‘acpi_tb_find_table’ at drivers/acpi/acpica/tbfind.c:60:2:
include/linux/fortify-string.h:68:30: error: ‘__builtin_strncpy’ specified
bound 6 equals destination size [-Werror=stringop-truncation]

Use strscpy to avoid this warning and is safer.

Signed-off-by: Su Hui <suhui@nfschina.com>
---
 drivers/acpi/acpica/tbfind.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c
index 1c1b2e284bd9..5536d1755188 100644
--- a/drivers/acpi/acpica/tbfind.c
+++ b/drivers/acpi/acpica/tbfind.c
@@ -57,8 +57,8 @@ acpi_tb_find_table(char *signature,
 
 	memset(&header, 0, sizeof(struct acpi_table_header));
 	ACPI_COPY_NAMESEG(header.signature, signature);
-	strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
-	strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
+	strscpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
+	strscpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
 
 	/* Search for the table */
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] ACPICA: Use strscpy to replace strncpy
  2023-08-31  7:34 [PATCH 1/2] ACPICA: Use strscpy to replace strncpy Su Hui
@ 2023-08-31  9:35 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2023-08-31  9:35 UTC (permalink / raw)
  To: Su Hui
  Cc: robert.moore, rafael.j.wysocki, lenb, linux-acpi, acpica-devel,
	linux-kernel, kernel-janitors

On Thu, Aug 31, 2023 at 9:35 AM Su Hui <suhui@nfschina.com> wrote:
>
> With gcc and W=1 option to compile kernel, warning happens:
>
> inlined from ‘acpi_tb_find_table’ at drivers/acpi/acpica/tbfind.c:60:2:
> include/linux/fortify-string.h:68:30: error: ‘__builtin_strncpy’ specified
> bound 6 equals destination size [-Werror=stringop-truncation]
>
> Use strscpy to avoid this warning and is safer.
>
> Signed-off-by: Su Hui <suhui@nfschina.com>

Please see

https://lore.kernel.org/linux-acpi/202308241612.DFE4119@keescook/

> ---
>  drivers/acpi/acpica/tbfind.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/acpica/tbfind.c b/drivers/acpi/acpica/tbfind.c
> index 1c1b2e284bd9..5536d1755188 100644
> --- a/drivers/acpi/acpica/tbfind.c
> +++ b/drivers/acpi/acpica/tbfind.c
> @@ -57,8 +57,8 @@ acpi_tb_find_table(char *signature,
>
>         memset(&header, 0, sizeof(struct acpi_table_header));
>         ACPI_COPY_NAMESEG(header.signature, signature);
> -       strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
> -       strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
> +       strscpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE);
> +       strscpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE);
>
>         /* Search for the table */
>
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-31  9:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31  7:34 [PATCH 1/2] ACPICA: Use strscpy to replace strncpy Su Hui
2023-08-31  9:35 ` Rafael J. Wysocki

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).