public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/power/acpi: Replace strcpy/strcat with snprintf in osunixdir.c
@ 2026-02-01 18:16 Sumeet Pawnikar
  2026-02-13 13:30 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Sumeet Pawnikar @ 2026-02-01 18:16 UTC (permalink / raw)
  To: rafael, robert.moore, lenb, linux-acpi, acpica-devel
  Cc: linux-kernel, sumeet4linux

Replace unsafe strcpy() and strcat() calls with snprintf() in
osunixdir.c to prevent potential buffer overflow vulnerabilities
when constructing file paths.

The snprintf() function performs automatic bounds checking to ensure
the destination buffer is not overflowed.

No functional change.

Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com>
---
 .../power/acpi/os_specific/service_layers/osunixdir.c  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/power/acpi/os_specific/service_layers/osunixdir.c b/tools/power/acpi/os_specific/service_layers/osunixdir.c
index b9bb83116549..5dc960c6b376 100644
--- a/tools/power/acpi/os_specific/service_layers/osunixdir.c
+++ b/tools/power/acpi/os_specific/service_layers/osunixdir.c
@@ -113,9 +113,8 @@ char *acpi_os_get_next_filename(void *dir_handle)
 				return (NULL);
 			}
 
-			strcpy(temp_str, external_info->dir_pathname);
-			strcat(temp_str, "/");
-			strcat(temp_str, dir_entry->d_name);
+			snprintf(temp_str, str_len, "%s/%s",
+				 external_info->dir_pathname, dir_entry->d_name);
 
 			err = stat(temp_str, &temp_stat);
 			if (err == -1) {
@@ -137,8 +136,9 @@ char *acpi_os_get_next_filename(void *dir_handle)
 
 				/* copy to a temp buffer because dir_entry struct is on the stack */
 
-				strcpy(external_info->temp_buffer,
-				       dir_entry->d_name);
+				snprintf(external_info->temp_buffer,
+					 sizeof(external_info->temp_buffer),
+					 "%s", dir_entry->d_name);
 				return (external_info->temp_buffer);
 			}
 		}
-- 
2.43.0


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

* Re: [PATCH] tools/power/acpi: Replace strcpy/strcat with snprintf in osunixdir.c
  2026-02-01 18:16 [PATCH] tools/power/acpi: Replace strcpy/strcat with snprintf in osunixdir.c Sumeet Pawnikar
@ 2026-02-13 13:30 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2026-02-13 13:30 UTC (permalink / raw)
  To: Sumeet Pawnikar
  Cc: rafael, robert.moore, lenb, linux-acpi, acpica-devel,
	linux-kernel

On Sun, Feb 1, 2026 at 7:17 PM Sumeet Pawnikar <sumeet4linux@gmail.com> wrote:
>
> Replace unsafe strcpy() and strcat() calls with snprintf() in
> osunixdir.c to prevent potential buffer overflow vulnerabilities
> when constructing file paths.
>
> The snprintf() function performs automatic bounds checking to ensure
> the destination buffer is not overflowed.
>
> No functional change.
>
> Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com>

The ACPI tools come from ACPICA, so if you want to make changes to
them, you need to do that in upstream ACPICA.

Refer to Documentation/driver-api/acpi/linuxized-acpica.rst for more
information.

Thanks!

> ---
>  .../power/acpi/os_specific/service_layers/osunixdir.c  | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/power/acpi/os_specific/service_layers/osunixdir.c b/tools/power/acpi/os_specific/service_layers/osunixdir.c
> index b9bb83116549..5dc960c6b376 100644
> --- a/tools/power/acpi/os_specific/service_layers/osunixdir.c
> +++ b/tools/power/acpi/os_specific/service_layers/osunixdir.c
> @@ -113,9 +113,8 @@ char *acpi_os_get_next_filename(void *dir_handle)
>                                 return (NULL);
>                         }
>
> -                       strcpy(temp_str, external_info->dir_pathname);
> -                       strcat(temp_str, "/");
> -                       strcat(temp_str, dir_entry->d_name);
> +                       snprintf(temp_str, str_len, "%s/%s",
> +                                external_info->dir_pathname, dir_entry->d_name);
>
>                         err = stat(temp_str, &temp_stat);
>                         if (err == -1) {
> @@ -137,8 +136,9 @@ char *acpi_os_get_next_filename(void *dir_handle)
>
>                                 /* copy to a temp buffer because dir_entry struct is on the stack */
>
> -                               strcpy(external_info->temp_buffer,
> -                                      dir_entry->d_name);
> +                               snprintf(external_info->temp_buffer,
> +                                        sizeof(external_info->temp_buffer),
> +                                        "%s", dir_entry->d_name);
>                                 return (external_info->temp_buffer);
>                         }
>                 }
> --
> 2.43.0
>
>

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

end of thread, other threads:[~2026-02-13 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-01 18:16 [PATCH] tools/power/acpi: Replace strcpy/strcat with snprintf in osunixdir.c Sumeet Pawnikar
2026-02-13 13:30 ` 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