Skip to contentSkip to conversation

perf tools: ensure comm properly terminated If threads in a multi-threaded process have names shorter than the main thread the comm for the named threads is not properly terminated.

PATCH Applied David Ahern 2 participants 3 messages Feb 24, 2012 – Mar 2, 2012 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: ensure comm properly terminated If threads in a multi-threaded process have names shorter than the main thread the comm for the named threads is not properly terminated.

e.g., for the process 'namedthreads' where each thread is named noploop%d where %d is the thread number:

Before:
perf script -f comm,tid,ip,sym,dso
noploop:4ads 21616 400a49 noploop (/tmp/namedthreads)
The 'ads' in the thread comm bleeds over from the process name.

After:
perf script -f comm,tid,ip,sym,dso
noploop:4 21616 400a49 noploop (/tmp/namedthreads)

---
 tools/perf/util/event.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/event.c +1 -0
index 2044324..2a6f33c 100644
@@ -74,6 +74,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
 			if (size >= len)
 				size = len - 1;
 			memcpy(comm, name, size);
+			comm[size] = '\0';
 
 		} else if (memcmp(bf, "Tgid:", 5) == 0) {
 			char *tgids = bf + 5;
Signature · 1 line
1.7.5.4
#1 lore raw

Em Fri, Feb 24, 2012 at 12:31:38PM -0700, David Ahern escreveu:

Quoted 11 lines

e.g., for the process 'namedthreads' where each thread is named noploop%d where %d is the thread number:

Before:
perf script -f comm,tid,ip,sym,dso
noploop:4ads 21616 400a49 noploop (/tmp/namedthreads)
The 'ads' in the thread comm bleeds over from the process name.

After:
perf script -f comm,tid,ip,sym,dso
noploop:4 21616 400a49 noploop (/tmp/namedthreads)

Thanks, applied to perf/urgent.

- Arnaldo

#2 lore raw

[tip:perf/urgent] perf tools: Ensure comm string is properly terminated

In reply to David Ahern
Commit-ID:  cfbd70c17c4535e64be92ea442a2a45078a18184
Gitweb:     http://git.kernel.org/tip/cfbd70c17c4535e64be92ea442a2a45078a18184
Author:     David Ahern <[email protected]>
AuthorDate: Fri, 24 Feb 2012 12:31:38 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 29 Feb 2012 18:29:45 -0300

perf tools: Ensure comm string is properly terminated

If threads in a multi-threaded process have names shorter than the main thread the comm for the named threads is not properly terminated.

E.g., for the process 'namedthreads' where each thread is named noploop%d where %d is the thread number:

Before:
perf script -f comm,tid,ip,sym,dso
noploop:4ads 21616 400a49 noploop (/tmp/namedthreads)
The 'ads' in the thread comm bleeds over from the process name.

After:
perf script -f comm,tid,ip,sym,dso
noploop:4 21616 400a49 noploop (/tmp/namedthreads)

---
 tools/perf/util/event.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/event.c +1 -0
index 2044324..2a6f33c 100644
@@ -74,6 +74,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
 			if (size >= len)
 				size = len - 1;
 			memcpy(comm, name, size);
+			comm[size] = '\0';
 
 		} else if (memcmp(bf, "Tgid:", 5) == 0) {
 			char *tgids = bf + 5;