* [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool
@ 2025-11-17 6:50 Dharanitharan R
2025-11-17 12:33 ` Greg KH
2025-11-18 7:36 ` Dan Carpenter
0 siblings, 2 replies; 3+ messages in thread
From: Dharanitharan R @ 2025-11-17 6:50 UTC (permalink / raw)
To: johan, elder, gregkh; +Cc: greybus-dev, linux-staging, Dharanitharan R
The sample userspace firmware-management tool uses strncpy() to copy
firmware tags. strncpy() does not guarantee null-termination and can
leave buffers unterminated. For userspace code, strlcpy() is the
recommended safe alternative.
Replace all strncpy() calls with strlcpy().
Signed-off-by: Dharanitharan <dharanitharan725@gmail.com>
---
.../greybus/Documentation/firmware/firmware.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/greybus/Documentation/firmware/firmware.c b/drivers/staging/greybus/Documentation/firmware/firmware.c
index 3b35ef6d4adb..224eb8f4e39c 100644
--- a/drivers/staging/greybus/Documentation/firmware/firmware.c
+++ b/drivers/staging/greybus/Documentation/firmware/firmware.c
@@ -63,8 +63,9 @@ static int update_intf_firmware(int fd)
intf_load.major = 0;
intf_load.minor = 0;
- strncpy((char *)&intf_load.firmware_tag, firmware_tag,
- GB_FIRMWARE_U_TAG_MAX_SIZE);
+ strlcpy(intf_load.firmware_tag, firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE);
+
ret = ioctl(fd, FW_MGMT_IOC_INTF_LOAD_AND_VALIDATE, &intf_load);
if (ret < 0) {
@@ -101,8 +102,9 @@ 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,
- GB_FIRMWARE_U_TAG_MAX_SIZE);
+ strlcpy(backend_fw_info.firmware_tag, firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE);
+
retry_fw_version:
ret = ioctl(fd, FW_MGMT_IOC_GET_BACKEND_FW, &backend_fw_info);
@@ -129,8 +131,8 @@ 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,
- GB_FIRMWARE_U_TAG_MAX_SIZE);
+ strlcpy(backend_update.firmware_tag, firmware_tag,
+ GB_FIRMWARE_U_TAG_MAX_SIZE);
retry_fw_update:
backend_update.status = 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool
2025-11-17 6:50 [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool Dharanitharan R
@ 2025-11-17 12:33 ` Greg KH
2025-11-18 7:36 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2025-11-17 12:33 UTC (permalink / raw)
To: Dharanitharan R; +Cc: johan, elder, greybus-dev, linux-staging
On Mon, Nov 17, 2025 at 06:50:03AM +0000, Dharanitharan R wrote:
> The sample userspace firmware-management tool uses strncpy() to copy
> firmware tags. strncpy() does not guarantee null-termination and can
> leave buffers unterminated. For userspace code, strlcpy() is the
> recommended safe alternative.
>
> Replace all strncpy() calls with strlcpy().
>
> Signed-off-by: Dharanitharan <dharanitharan725@gmail.com>
> ---
> .../greybus/Documentation/firmware/firmware.c | 14 ++++++++------
> 1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/greybus/Documentation/firmware/firmware.c b/drivers/staging/greybus/Documentation/firmware/firmware.c
> index 3b35ef6d4adb..224eb8f4e39c 100644
> --- a/drivers/staging/greybus/Documentation/firmware/firmware.c
> +++ b/drivers/staging/greybus/Documentation/firmware/firmware.c
> @@ -63,8 +63,9 @@ static int update_intf_firmware(int fd)
> intf_load.major = 0;
> intf_load.minor = 0;
>
> - strncpy((char *)&intf_load.firmware_tag, firmware_tag,
> - GB_FIRMWARE_U_TAG_MAX_SIZE);
> + strlcpy(intf_load.firmware_tag, firmware_tag,
> + GB_FIRMWARE_U_TAG_MAX_SIZE);
> +
What happened to the indentation?
:(
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool
2025-11-17 6:50 [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool Dharanitharan R
2025-11-17 12:33 ` Greg KH
@ 2025-11-18 7:36 ` Dan Carpenter
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-11-18 7:36 UTC (permalink / raw)
To: Dharanitharan R; +Cc: johan, elder, gregkh, greybus-dev, linux-staging
On Mon, Nov 17, 2025 at 06:50:03AM +0000, Dharanitharan R wrote:
> The sample userspace firmware-management tool uses strncpy() to copy
> firmware tags. strncpy() does not guarantee null-termination and can
> leave buffers unterminated. For userspace code, strlcpy() is the
> recommended safe alternative.
>
> Replace all strncpy() calls with strlcpy().
Don't use strlcpy(). Either use strscpy() or strscpy_pad() as
appropriate. I wrote a blog about this which may be useful.
https://staticthinking.wordpress.com/2023/10/30/strcpy-strncpy-strlcpy-and-strscpy/
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-18 7:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-17 6:50 [PATCH] staging: greybus: replace strncpy() with strlcpy() in firmware test tool Dharanitharan R
2025-11-17 12:33 ` Greg KH
2025-11-18 7:36 ` Dan Carpenter
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).