Re: [PATCH] staging: greybus: documentation: replace strncpy() with strscpy_pad()

From: Dan Carpenter

Date: Tue Oct 14 2025 - 13:13:51 EST


On Tue, Oct 14, 2025 at 12:10:50PM -0400, Vivek BalachandharTN wrote:
> Hi Dan,
>
> Thanks again—confirmed the structs are zero-initialized before the copy.
>
> Would a minimal fix that guarantees NUL-termination be acceptable, e.g.:
>
> strncpy((char *)&intf_load.firmware_tag, firmware_tag,
>         GB_FIRMWARE_U_TAG_MAX_SIZE - 1);
> ((char *)&intf_load.firmware_tag)[GB_FIRMWARE_U_TAG_MAX_SIZE - 1] = '\0';
>
> I can respin as v2 with the same change applied to the other two
> firmware_tag
> fields.

Sorry, I should have explained this at the start... The struct is
initialized to zero. The strncpy() copies at most
"GB_FIRMWARE_U_TAG_MAX_SIZE - 1" characters, meaning we never copy
anything to the last character which stays as zero.

regards,
dan carpenter