diff mbox series

media: media-device: use strlcpy() instead of strncpy()

Message ID 1515415259-195067-1-git-send-email-wangxiongfeng2@huawei.com
State New
Headers show
Series media: media-device: use strlcpy() instead of strncpy() | expand

Commit Message

Xiongfeng Wang Jan. 8, 2018, 12:40 p.m. UTC
From: Xiongfeng Wang <xiongfeng.wang@linaro.org>


gcc-8 reports

drivers/media/media-device.c: In function 'media_device_get_topology':
./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
bound 64 equals destination size [-Wstringop-truncation]

We need to use strlcpy() to make sure the dest string is nul-terminated.

Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>

---
 drivers/media/media-device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
1.8.3.1

Comments

Sakari Ailus Jan. 8, 2018, 3:10 p.m. UTC | #1
On Mon, Jan 08, 2018 at 08:40:59PM +0800, Xiongfeng Wang wrote:
> From: Xiongfeng Wang <xiongfeng.wang@linaro.org>

> 

> gcc-8 reports

> 

> drivers/media/media-device.c: In function 'media_device_get_topology':

> ./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified

> bound 64 equals destination size [-Wstringop-truncation]

> 

> We need to use strlcpy() to make sure the dest string is nul-terminated.

> 

> Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>


Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>


-- 
Sakari Ailus
e-mail: sakari.ailus@iki.fi
diff mbox series

Patch

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index e79f72b..f442444 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -255,7 +255,7 @@  static long media_device_get_topology(struct media_device *mdev,
 		memset(&kentity, 0, sizeof(kentity));
 		kentity.id = entity->graph_obj.id;
 		kentity.function = entity->function;
-		strncpy(kentity.name, entity->name,
+		strlcpy(kentity.name, entity->name,
 			sizeof(kentity.name));
 
 		if (copy_to_user(uentity, &kentity, sizeof(kentity)))