[OpenWrt-Devel] [PATCH] use strncpy instead of strcpy

Khem Raj raj.khem at gmail.com
Tue Dec 24 13:02:13 EST 2019


Fixes
error: '__builtin_strcpy' offset 6 from the object at 'attr' is out of the bounds of referenced subobject 'name' with type 'uint8_t[0]' {aka 'unsigned char[0]'} at offset 6 [-Werror=array-bounds]

Signed-off-by: Khem Raj <raj.khem at gmail.com>
---
 blobmsg.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/blobmsg.c b/blobmsg.c
index a860483..63fada8 100644
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -195,7 +195,8 @@ blobmsg_new(struct blob_buf *buf, int type, const char *name, int payload_len, v
 	attr->id_len |= be32_to_cpu(BLOB_ATTR_EXTENDED);
 	hdr = blob_data(attr);
 	hdr->namelen = cpu_to_be16(namelen);
-	strcpy((char *) hdr->name, (const char *)name);
+	hdr->name[strlen((char*)hdr->name)] = '\0';
+	strncpy((char *) hdr->name, (const char *)name, strlen((char*)hdr->name));
 	pad_end = *data = blobmsg_data(attr);
 	pad_start = (char *) &hdr->name[namelen];
 	if (pad_start < pad_end)
-- 
2.24.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list