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

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