Skip to contentSkip to conversation

staging: greybus: Replace strncpy with strscpy

PATCH In review Noah Techoueyres 2 participants 2 messages Aug 3 – Aug 8

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

PATCH 1/1 staging: greybus: Replace strncpy with strscpy

Replace deprecated strncpy() with strscpy() to improve string
handling safety. strscpy() guarantees null-termination and is the preferred function per the kernel string handling guidelines.

---
 drivers/staging/greybus/Documentation/firmware/firmware.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/Documentation/firmware/firmware.c +3 -3
index 3b35ef6d4adb..669185706744 100644
@@ -63,7 +63,7 @@ static int update_intf_firmware(int fd)
 	intf_load.major = 0;
 	intf_load.minor = 0;
 
-	strncpy((char *)&intf_load.firmware_tag, firmware_tag,
+	strscpy((char *)&intf_load.firmware_tag, firmware_tag,
 		GB_FIRMWARE_U_TAG_MAX_SIZE);
 
 	ret = ioctl(fd, FW_MGMT_IOC_INTF_LOAD_AND_VALIDATE, &intf_load);
@@ -101,7 +101,7 @@ static int update_backend_firmware(int fd)
 	/* Get Backend Firmware Version */
 	printf("Getting Backend Firmware Version\n");
 
-	strncpy((char *)&backend_fw_info.firmware_tag, firmware_tag,
+	strscpy((char *)&backend_fw_info.firmware_tag, firmware_tag,
 		GB_FIRMWARE_U_TAG_MAX_SIZE);
 
 retry_fw_version:
@@ -129,7 +129,7 @@ static int update_backend_firmware(int fd)
 	/* Try Backend Firmware Update over Unipro */
 	printf("Updating Backend Firmware\n");
 
-	strncpy((char *)&backend_update.firmware_tag, firmware_tag,
+	strscpy((char *)&backend_update.firmware_tag, firmware_tag,
 		GB_FIRMWARE_U_TAG_MAX_SIZE);
 
 retry_fw_update:
Signature · 1 line
2.43.0
#1 lore raw
Quoted 3 lines · Noah Techoueyres

Replace deprecated strncpy() with strscpy() to improve string
handling safety. strscpy() guarantees null-termination and is the preferred function per the kernel string handling guidelines.

This white space is weird. You did't try to compile your patch.

regards,
dan carpenter