Skip to contentSkip to conversation

ACPICA: Unbreak tools build after switching over to strscpy_pad()

PATCH In review Rafael J. Wysocki 3 participants 4 messages Jun 22 – Jun 23

Subsystems (2)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 ACPICA: Unbreak tools build after switching over to strscpy_pad()

From: Rafael J. Wysocki <[email protected]>

Commit 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()") switched over the ACPICA code in the kernel to using strscpy_pad() instead of a combination of strncpy() and manual NUL-termination of the destination string, but it overlooked the fact that tools also use the code in question and strscpy_pad() is not defined in those builds.

Address that by using the original ACPICA code in non-kernel builds.

Fixes 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()")
---
 drivers/acpi/acpica/utnonansi.c |   10 ++++++++++
 1 file changed, 9 insertions(+)
drivers/acpi/acpica/utnonansi.c +9 -0
@@ -168,7 +168,17 @@ void acpi_ut_safe_strncpy(char *dest, ch
 {
 	/* Always terminate destination string */
 
+#ifdef __KERNEL__
 	strscpy_pad(dest, source, dest_size);
+#else
+	/*
+	 * strscpy_pad() is not defined in ACPICA tools builds, so use strncpy()
+	 * and directly NUL-terminate the destination string in that case.
+	 */
+	strncpy(dest, source, dest_size);
+	dest[dest_size - 1] = 0;
+#endif
 }
 
 #endif
#1 lore raw

drivers/acpi/acpica/utnonansi.c void acpi_ut_safe_strncpy(char *dest, ch

Quoted 22 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()") switched over the ACPICA code in the kernel to using strscpy_pad() instead of a combination of strncpy() and manual NUL-termination of the destination string, but it overlooked the fact that tools also use the code in question and strscpy_pad() is not defined in those builds.

Address that by using the original ACPICA code in non-kernel builds.

Fixes 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()")
---
  drivers/acpi/acpica/utnonansi.c |   10 ++++++++++
  1 file changed, 9 insertions(+)
drivers/acpi/acpica/utnonansi.c +0 -0
@@ -168,7 +168,17 @@ void acpi_ut_safe_strncpy(char *dest, ch

Hmm, how could this become 17, provided you are adding 9 lines to 7 lines? Fixed to 16 and applied -- testing.

Quoted 19 lines
drivers/acpi/acpica/utnonansi.c +9 -0
  {
  	/* Always terminate destination string */
 
+#ifdef __KERNEL__
  	strscpy_pad(dest, source, dest_size);
+#else
+	/*
+	 * strscpy_pad() is not defined in ACPICA tools builds, so use strncpy()
+	 * and directly NUL-terminate the destination string in that case.
+	 */
+	strncpy(dest, source, dest_size);
+	dest[dest_size - 1] = 0;
+#endif
  }
 
  #endif
Signature · 2 lines
js
suse labs
author maintainer
#2 lore raw
Quoted 21 lines · Jiri Slaby
Quoted 19 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()") switched over the ACPICA code in the kernel to using strscpy_pad() instead of a combination of strncpy() and manual NUL-termination of the destination string, but it overlooked the fact that tools also use the code in question and strscpy_pad() is not defined in those builds.

Address that by using the original ACPICA code in non-kernel builds.

Fixes 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()")
---
  drivers/acpi/acpica/utnonansi.c |   10 ++++++++++
  1 file changed, 9 insertions(+)
Quoted 6 lines

drivers/acpi/acpica/utnonansi.c void acpi_ut_safe_strncpy(char *dest, ch

Quoted 3 lines
drivers/acpi/acpica/utnonansi.c +0 -0
@@ -168,7 +168,17 @@ void acpi_ut_safe_strncpy(char *dest, ch

Hmm, how could this become 17, provided you are adding 9 lines to 7 lines? Fixed to 16 and applied -- testing.

Yeah, I manually updated the comment and forgot to refresh the patch afterward. Sorry.

Quoted 24 lines
Quoted 9 lines
drivers/acpi/acpica/utnonansi.c +2 -0
  {
      /* Always terminate destination string */
 
+#ifdef __KERNEL__
      strscpy_pad(dest, source, dest_size);
+#else

drivers/acpi/acpica/utnonansi.c void acpi_ut_safe_strncpy(char *dest, ch · line 183

Quoted 10 lines
drivers/acpi/acpica/utnonansi.c +7 -0
+     /*
+      * strscpy_pad() is not defined in ACPICA tools builds, so use strncpy()
+      * and directly NUL-terminate the destination string in that case.
+      */
+     strncpy(dest, source, dest_size);
+     dest[dest_size - 1] = 0;
+#endif
  }
 
  #endif

--
js
suse labs

Reviewed-by on v1 1/1
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 97f7d3f9c9ac ("ACPICA: Replace strncpy() with strscpy_pad() in acpi_ut_safe_strncpy()") switched over the ACPICA code in the kernel to using strscpy_pad() instead of a combination of strncpy() and manual NUL-termination of the destination string, but it overlooked the fact that tools also use the code in question and strscpy_pad() is not defined in those builds.

Eek. Thanks for fixing this! (This looks almost exactly like the shared BPF header solution: non-kernel build just keeps using strncpy.)

Signature · 1 line
Kees Cook