]> granicus.if.org Git - psmisc/commitdiff
Set COMM_LEN to 18 to include brackets in name
authorCraig Small <csmall@users.sourceforge.net>
Fri, 27 Jan 2012 01:02:48 +0000 (12:02 +1100)
committerCraig Small <csmall@users.sourceforge.net>
Fri, 27 Jan 2012 01:02:48 +0000 (12:02 +1100)
Also use strncpy in case the command names grow.

src/comm.h
src/pstree.c

index 956383db32338297f7a7ce2b3ef49b437c9d73e5..2b780b0e18d0f89305b065ad94a729f7f5892be8 100644 (file)
@@ -1,18 +1,37 @@
-/* comm.h - command name length definition */
-
-/* Copyright 1995 Werner Almesberger. See file COPYING for details. */
-
+/*
+ * comm.h - command name length definition 
+ *
+ * Copyright 1995 Werner Almesberger
+ * Copyright 2012 Craig Small <csmall@enc.com.au>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #ifndef COMM_H
 #define COMM_H
 
-#if 0                          /* broken in 1.3.xx */
-#include <linux/sched.h>
-#define COMM_LEN sizeof(dummy.comm)
-extern struct task_struct dummy;
-#else
-#define COMM_LEN 16            /* synchronize with size of comm in struct task_struct in
-                                  /usr/include/linux/sched.h */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
 #endif
 
+/*
+ * COMM_LEN should be the same size as TASK_COMM_LEN in the Linux source
+ * at include/linux/sched.h
+ * However, that doesn't include the brackets that may be in the field.
+ */
+#define COMM_LEN 18
+
 #endif
index 452f82371c96df1291e4085fbfd95acfaf26fafe..3129f7636e6353b22f1de8f6f354471d02a9e480 100644 (file)
@@ -264,7 +264,7 @@ static PROC *new_proc(const char *comm, pid_t pid, uid_t uid)
         perror("malloc");
         exit(1);
     }
-    strcpy(new->comm, comm);
+    strncpy(new->comm, comm, COMM_LEN);
     new->pid = pid;
     new->uid = uid;
     new->flags = 0;
@@ -352,7 +352,7 @@ add_proc(const char *comm, pid_t pid, pid_t ppid, uid_t uid,
         this = new_proc(comm, pid, uid);
 #endif                                /*WITH_SELINUX */
     else {
-        strcpy(this->comm, comm);
+        strncpy(this->comm, comm, COMM_LEN);
         this->uid = uid;
     }
     if (args)