Skip to content

Commit 08de420

Browse files
keesandersson
authored andcommitted
rpmsg: glink: Replace strncpy() with strscpy_pad()
The use of strncpy() is considered deprecated for NUL-terminated strings[1]. Replace strncpy() with strscpy_pad() (as it seems this case expects the NUL padding to fill the allocation following the flexible array). This additionally silences a warning seen when building under -Warray-bounds: ./include/linux/fortify-string.h:38:30: warning: '__builtin_strncpy' offset 24 from the object at '__mptr' is out of the bounds of referenced subobject 'data' with type 'u8[]' {aka 'unsigned char[]'} at offset 24 [-Warray-bounds] 38 | #define __underlying_strncpy __builtin_strncpy | ^ ./include/linux/fortify-string.h:50:9: note: in expansion of macro '__underlying_strncpy' 50 | return __underlying_strncpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~~ drivers/rpmsg/qcom_glink_native.c: In function 'qcom_glink_work': drivers/rpmsg/qcom_glink_native.c:36:5: note: subobject 'data' declared here 36 | u8 data[]; | ^~~~ [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings Cc: Andy Gross <[email protected]> Cc: Bjorn Andersson <[email protected]> Cc: Ohad Ben-Cohen <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/lkml/20210728020745.GB35706@embeddedor Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 6880fa6 commit 08de420

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/rpmsg/qcom_glink_native.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ static int qcom_glink_rx_open(struct qcom_glink *glink, unsigned int rcid,
14401440
}
14411441

14421442
rpdev->ept = &channel->ept;
1443-
strncpy(rpdev->id.name, name, RPMSG_NAME_SIZE);
1443+
strscpy_pad(rpdev->id.name, name, RPMSG_NAME_SIZE);
14441444
rpdev->src = RPMSG_ADDR_ANY;
14451445
rpdev->dst = RPMSG_ADDR_ANY;
14461446
rpdev->ops = &glink_device_ops;

0 commit comments

Comments
 (0)