summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger2013-06-19 11:29:57 -0400
committerMike Frysinger2013-06-19 11:29:57 -0400
commitfea25880212dd934c7e17fce8a299f9184933f6b (patch)
tree3918cd01e1773ab7a187c06a25ebe7ac2d6e8f24
parent5a7e3376b7011d3f8f2591d9dead4fc580619096 (diff)
downloadbusybox-fea25880212dd934c7e17fce8a299f9184933f6b.zip
busybox-fea25880212dd934c7e17fce8a299f9184933f6b.tar.gz
pstree: stop truncating thread names
This also fixes a minor buffer overflow when displaying threads as add_proc() only expects COMM_LEN bytes, but we give it one more than that. Reported-by: Dag Wieers <dag@wieers.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--procps/pstree.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/procps/pstree.c b/procps/pstree.c
index 8ba3079..ea690a9 100644
--- a/procps/pstree.c
+++ b/procps/pstree.c
@@ -34,8 +34,15 @@
struct child;
+#ifdef ENABLE_FEATURE_SHOW_THREADS
+/* For threads, we add {...} around the comm, so we need two extra bytes */
+# define COMM_DISP_LEN (COMM_LEN + 2)
+#else
+# define COMM_DISP_LEN COMM_LEN
+#endif
+
typedef struct proc {
- char comm[COMM_LEN + 1];
+ char comm[COMM_DISP_LEN + 1];
// char flags; - unused, delete?
pid_t pid;
uid_t uid;
@@ -341,8 +348,8 @@ static void dump_by_user(PROC *current, uid_t uid)
#if ENABLE_FEATURE_SHOW_THREADS
static void handle_thread(const char *comm, pid_t pid, pid_t ppid, uid_t uid)
{
- char threadname[COMM_LEN + 2];
- sprintf(threadname, "{%.*s}", COMM_LEN - 2, comm);
+ char threadname[COMM_DISP_LEN + 1];
+ sprintf(threadname, "{%.*s}", (int)sizeof(threadname) - 1, comm);
add_proc(threadname, pid, ppid, uid/*, 1*/);
}
#endif