Skip to contentSkip to conversation

staging: most: protect potential string overflow

PATCH In review Bo YU 2 participants 3 messages Apr 23, 2019 – Apr 26, 2019

Subsystems (2)
lore
Share & tools
lore

Bo YU

author
#0 lore raw

PATCH 1/1 staging: most: protect potential string overflow

There maybe cause potential string overflow issue due to use strcpy without checking the length

Detected By CoversityScan CID# 1444760

Fixes 131ac62253dba:(staging: most: core: use device description as name)
---
 drivers/staging/most/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/most/core.c +1 -1
index 956daf8c3bd2..0f26cebac91a 100644
@@ -1431,7 +1431,7 @@ int most_register_interface(struct most_interface *iface)
 
 	INIT_LIST_HEAD(&iface->p->channel_list);
 	iface->p->dev_id = id;
-	strcpy(iface->p->name, iface->description);
+	strlcpy(iface->p->name, iface->description, sizeof(iface->p->name));
 	iface->dev.init_name = iface->p->name;
 	iface->dev.bus = &mc.bus;
 	iface->dev.parent = &mc.dev;
Signature · 1 line
2.11.0
#1 lore raw
Quoted 6 lines · Bo YU

There maybe cause potential string overflow issue due to use strcpy without checking the length

Detected By CoversityScan CID# 1444760

Fixes 131ac62253dba:(staging: most: core: use device description as name)

It doesn't really fix anything, it just silences a static checker warning.

Quoted 10 lines
---
 drivers/staging/most/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/most/core.c +0 -0
index 956daf8c3bd2..0f26cebac91a 100644

drivers/staging/most/core.c int most_register_interface(struct most_interface *iface) · line 1434

Quoted 5 lines
drivers/staging/most/core.c +1 -1
@@ -1431,7 +1431,7 @@ int most_register_interface(struct most_interface *iface)
 
 	INIT_LIST_HEAD(&iface->p->channel_list);
 	iface->p->dev_id = id;
-	strcpy(iface->p->name, iface->description);
+	strlcpy(iface->p->name, iface->description, sizeof(iface->p->name));

We prefer strscpy() more than strlcpy() these days.

regards,
dan carpenter

author
#2 lore raw
Quoted 23 lines · Dan Carpenter
Quoted 6 lines · Bo YU

There maybe cause potential string overflow issue due to use strcpy without checking the length

Detected By CoversityScan CID# 1444760

Fixes 131ac62253dba:(staging: most: core: use device description as name)

It doesn't really fix anything, it just silences a static checker warning.

Quoted 11 lines
---
 drivers/staging/most/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/most/core.c +0 -0
index 956daf8c3bd2..0f26cebac91a 100644
@@ -1431,7 +1431,7 @@ int most_register_interface(struct most_interface *iface)
 
Quoted 6 lines

drivers/staging/most/core.c int most_register_interface(struct most_interface *iface) · line 1434

Quoted 4 lines
drivers/staging/most/core.c +1 -1
      INIT_LIST_HEAD(&iface->p->channel_list);
      iface->p->dev_id = id;
-     strcpy(iface->p->name, iface->description);
+     strlcpy(iface->p->name, iface->description, sizeof(iface->p->name));

We prefer strscpy() more than strlcpy() these days.

Ok,will try it.
Thanks,

Quoted 4 lines

regards,
dan carpenter