public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel: events: strncpy, always be sure of NUL terminated.
@ 2013-04-08  3:48 Chen Gang
  2013-04-08 15:29 ` [tip:perf/urgent] perf: Fix strncpy() use, always make sure it' s " tip-bot for Chen Gang
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Gang @ 2013-04-08  3:48 UTC (permalink / raw)
  To: a.p.zijlstra@chello.nl, paulus@samba.org, mingo@redhat.com,
	acme@ghostprotocols.net
  Cc: linux-kernel@vger.kernel.org


  for NUL terminated string, always be sure of '\0' at the end.
  
  in our case, need return value, so still use strncpy
    (strlcpy return the size, not the pointer)

Signed-off-by: Chen Gang <gang.chen@asianux.com>
---
 kernel/events/core.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 4757941..bdc0e25 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4752,7 +4752,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
 	} else {
 		if (arch_vma_name(mmap_event->vma)) {
 			name = strncpy(tmp, arch_vma_name(mmap_event->vma),
-				       sizeof(tmp));
+				       sizeof(tmp) - 1);
+			tmp[sizeof(tmp) - 1] = '\0';
 			goto got_name;
 		}
 
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip:perf/urgent] perf: Fix strncpy() use, always make sure it' s NUL terminated
  2013-04-08  3:48 [PATCH] kernel: events: strncpy, always be sure of NUL terminated Chen Gang
@ 2013-04-08 15:29 ` tip-bot for Chen Gang
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Chen Gang @ 2013-04-08 15:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, paulus, hpa, mingo, a.p.zijlstra, acme, gang.chen,
	tglx

Commit-ID:  c97847d2f0eb77c806e650e04d9bbcf79fa05730
Gitweb:     http://git.kernel.org/tip/c97847d2f0eb77c806e650e04d9bbcf79fa05730
Author:     Chen Gang <gang.chen@asianux.com>
AuthorDate: Mon, 8 Apr 2013 11:48:27 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 8 Apr 2013 13:26:55 +0200

perf: Fix strncpy() use, always make sure it's NUL terminated

For NUL terminated string, always make sure that there's '\0' at the end.

In our case we need a return value, so still use strncpy() and
fix up the tail explicitly.

(strlcpy() returns the size, not the pointer)

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Cc: a.p.zijlstra@chello.nl <a.p.zijlstra@chello.nl>
Cc: paulus@samba.org <paulus@samba.org>
Cc: acme@ghostprotocols.net <acme@ghostprotocols.net>
Link: http://lkml.kernel.org/r/51623E0B.7070101@asianux.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/events/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 59412d0..7f0d67e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4737,7 +4737,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
 	} else {
 		if (arch_vma_name(mmap_event->vma)) {
 			name = strncpy(tmp, arch_vma_name(mmap_event->vma),
-				       sizeof(tmp));
+				       sizeof(tmp) - 1);
+			tmp[sizeof(tmp) - 1] = '\0';
 			goto got_name;
 		}
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-04-08 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-08  3:48 [PATCH] kernel: events: strncpy, always be sure of NUL terminated Chen Gang
2013-04-08 15:29 ` [tip:perf/urgent] perf: Fix strncpy() use, always make sure it' s " tip-bot for Chen Gang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox