Skip to contentSkip to conversation

ARM:mach-msm: seting tail NUL after strncpy

PATCH New Chen Gang 4 participants 7 messages Jan 30, 2013 – Feb 1, 2013

Subsystems (3)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

temp need NUL terminated, or next ptr may cause issue.

---
 arch/arm/mach-msm/clock-debug.c |    2 ++
 1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/arch/arm/mach-msm/clock-debug.c
index 4886404..bdca900 100644

arch/arm/mach-msm/clock-debug.c +2 -0
@@ -105,6 +105,8 @@ int __init clock_debug_add(struct clk *clock)
 		return -ENOMEM;
 
 	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+	temp[ARRAY_SIZE(temp)-1] = '\0';
+
 	for (ptr = temp; *ptr; ptr++)
 		*ptr = tolower(*ptr);
 
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

Quoted 13 lines · Chen Gang

temp need NUL terminated, or next ptr may cause issue.

---
 arch/arm/mach-msm/clock-debug.c |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-msm/clock-debug.c +0 -0
index 4886404..bdca900 100644

arch/arm/mach-msm/clock-debug.c int __init clock_debug_add(struct clk *clock) · line 111

Quoted 7 lines
arch/arm/mach-msm/clock-debug.c +2 -0
@@ -105,6 +105,8 @@ int __init clock_debug_add(struct clk *clock)
 		return -ENOMEM;
 
 	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+	temp[ARRAY_SIZE(temp)-1] = '\0';
+
 	for (ptr = temp; *ptr; ptr++)
 		*ptr = tolower(*ptr);

Maybe use strlcpy() instead?

Bj?rn

author
#2 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

? 2013?01?30? 17:19, Bj?rn Mork ??:

Quoted 1 line

Maybe use strlcpy() instead?

ok, I will send patch v2.

it will be "strlcpy(temp, clock->dbg_name, ARRAY_SIZE(temp));"

thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#3 lore raw

PATCH v2 1/1 ARM:mach-msm: using strlcpy instead lof strncpy

In reply to Bjørn Mork

The fields must be null-terminated, or next ptr, will cause issue

---
 arch/arm/mach-msm/clock-debug.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-msm/clock-debug.c +2 -1
index 4886404..c40dcaf 100644
@@ -17,6 +17,7 @@
 #include <linux/module.h>
 #include <linux/ctype.h>
 #include <linux/debugfs.h>
+#include <linux/string.h>
 #include <linux/clk.h>
 #include "clock.h"
 
@@ -104,7 +105,7 @@ int __init clock_debug_add(struct clk *clock)
 	if (!debugfs_base)
 		return -ENOMEM;
 
-	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+	strlcpy(temp, clock->dbg_name, ARRAY_SIZE(temp));
 	for (ptr = temp; *ptr; ptr++)
 		*ptr = tolower(*ptr);
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

In reply to Chen Gang
Quoted 13 lines · Chen Gang

temp need NUL terminated, or next ptr may cause issue.

---
 arch/arm/mach-msm/clock-debug.c |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-msm/clock-debug.c +0 -0
index 4886404..bdca900 100644

arch/arm/mach-msm/clock-debug.c int __init clock_debug_add(struct clk *clock) · line 110

Quoted 6 lines
arch/arm/mach-msm/clock-debug.c +2 -0
@@ -105,6 +105,8 @@ int __init clock_debug_add(struct clk *clock)
 		return -ENOMEM;
 
 	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+	temp[ARRAY_SIZE(temp)-1] = '\0';
+
 	for (ptr = temp; *ptr; ptr++)

I believe that Stephen Boyd is putting some significant work into this code. Stephen, can you see if this bug is still in your current version of the code, and make sure that it is fixed there?

Thanks,
David

Signature · 3 lines
sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

Quoted 17 lines · David Brown
Quoted 15 lines · Chen Gang

temp need NUL terminated, or next ptr may cause issue.

---
 arch/arm/mach-msm/clock-debug.c |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-msm/clock-debug.c +0 -0
index 4886404..bdca900 100644
@@ -105,6 +105,8 @@ int __init clock_debug_add(struct clk *clock)
 		return -ENOMEM;
 
Quoted 8 lines

arch/arm/mach-msm/clock-debug.c int __init clock_debug_add(struct clk *clock) · line 110

Quoted 4 lines
arch/arm/mach-msm/clock-debug.c +2 -0
 	strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+	temp[ARRAY_SIZE(temp)-1] = '\0';
+
 	for (ptr = temp; *ptr; ptr++)

I believe that Stephen Boyd is putting some significant work into this code. Stephen, can you see if this bug is still in your current version of the code, and make sure that it is fixed there?

This entire file is deleted in my set of patches that moves the current MSM clock code to the common clock framework.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
author
#6 lore raw

PATCH 1/1 ARM:mach-msm: seting tail NUL after strncpy

? 2013?01?31? 05:59, Stephen Boyd ??:

Quoted 9 lines · David Brown
Quoted 4 lines

I believe that Stephen Boyd is putting some significant work into this code. Stephen, can you see if this bug is still in your current version of the code, and make sure that it is fixed there?

This entire file is deleted in my set of patches that moves the current MSM clock code to the common clock framework.

ok, thank you.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation