Skip to contentSkip to conversation

arch: mips: lantiq: using strlcpy() instead of strncpy()

PATCH In review Chen Gang 2 participants 3 messages May 26, 2013 – May 29, 2013

Subsystems (3)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 arch: mips: lantiq: using strlcpy() instead of strncpy()

'compatible' is used by strlen() in __of_device_is_compatible().

So for NUL terminated string, need always be sure of ended by zero.

'of_ids' is not a structure in "include/uapi/*", so not need initialize all bytes, just use strlcpy() instead of strncpy().

---
 arch/mips/lantiq/prom.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/mips/lantiq/prom.c +1 -1
index 9f9e875..49c4603 100644
@@ -112,7 +112,7 @@ int __init plat_of_setup(void)
 	if (!of_have_populated_dt())
 		panic("device tree not present");
 
-	strncpy(of_ids[0].compatible, soc_info.compatible,
+	strlcpy(of_ids[0].compatible, soc_info.compatible,
 		sizeof(of_ids[0].compatible));
 	strncpy(of_ids[1].compatible, "simple-bus",
 		sizeof(of_ids[1].compatible));
Signature · 1 line
1.7.7.6
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Chen Gang

'compatible' is used by strlen() in __of_device_is_compatible().

So for NUL terminated string, need always be sure of ended by zero.

'of_ids' is not a structure in "include/uapi/*", so not need initialize all bytes, just use strlcpy() instead of strncpy().

Quoted 17 lines
---
  arch/mips/lantiq/prom.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
arch/mips/lantiq/prom.c +1 -1
index 9f9e875..49c4603 100644
@@ -112,7 +112,7 @@ int __init plat_of_setup(void)
  	if (!of_have_populated_dt())
  		panic("device tree not present");
 
-	strncpy(of_ids[0].compatible, soc_info.compatible,
+	strlcpy(of_ids[0].compatible, soc_info.compatible,
  		sizeof(of_ids[0].compatible));
  	strncpy(of_ids[1].compatible, "simple-bus",
  		sizeof(of_ids[1].compatible));
author
#2 lore raw
Quoted 5 lines · John Crispin
Quoted 4 lines · Chen Gang

'compatible' is used by strlen() in __of_device_is_compatible().

So for NUL terminated string, need always be sure of ended by zero.

Quoted 7 lines
Quoted 5 lines

'of_ids' is not a structure in "include/uapi/*", so not need initialize all bytes, just use strlcpy() instead of strncpy().

Thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation