Skip to contentSkip to conversation

sonypi: use strscpy() in sonypi_acpi_probe

PATCH In review Thorsten Blum 3 participants 3 messages Apr 24 – Apr 28

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sonypi: use strscpy() in sonypi_acpi_probe

strcpy() has been deprecated¹ because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices.

¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

---
Based on linux-next and the new function name sonypi_acpi_probe().

---
 drivers/char/sonypi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/char/sonypi.c +3 -2
index ccda997a9098..959949f04f7d 100644
@@ -37,6 +37,7 @@
 #include <linux/kfifo.h>
 #include <linux/platform_device.h>
 #include <linux/gfp.h>
+#include <linux/string.h>
 #include <linux/string_choices.h>
 
 #include <linux/uaccess.h>
@@ -1120,8 +1121,8 @@ static int sonypi_acpi_probe(struct platform_device *pdev)
 	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 
 	sonypi_acpi_device = device;
-	strcpy(acpi_device_name(device), "Sony laptop hotkeys");
-	strcpy(acpi_device_class(device), "sony/hotkey");
+	strscpy(acpi_device_name(device), "Sony laptop hotkeys");
+	strscpy(acpi_device_class(device), "sony/hotkey");
 	return 0;
 }
 
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Thorsten Blum

strcpy() has been deprecated¹ because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices.

¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

---
Based on linux-next and the new function name sonypi_acpi_probe().

maintainer
#2 lore raw
In reply to Thorsten Blum
Quoted 8 lines · Thorsten Blum

strcpy() has been deprecated¹ because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices.

¹ https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] sonypi: use strscpy() in sonypi_acpi_probe

      commit: b54a4676b3069c9a8cc68e07122e6438491a3353

--
i.