]> granicus.if.org Git - psmisc/commitdiff
Better comm_len fix
authorCraig Small <csmall@users.sourceforge.net>
Thu, 9 Feb 2012 20:03:34 +0000 (07:03 +1100)
committerCraig Small <csmall@users.sourceforge.net>
Thu, 9 Feb 2012 20:03:34 +0000 (07:03 +1100)
The previous fix for comm_len broke checks for process exactly the right
length, this one fixes the original problem and doesn't break that
situation.

Added a variable to the conditional STAT code that was previously
outside the #ifdef and gave an unsed variable warning.

configure.ac
src/comm.h
src/fuser.c
src/pstree.c

index e7e86fb68629175657ab89b69967b2a14192bdf6..0615f5f04ebb479d5a53ca99c6c005b6d9afc414 100644 (file)
@@ -1,5 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
-AC_PREREQ(2.61)
+AC_PREREQ([2.68])
+AC_CONFIG_MACRO_DIR([m4])
 AC_INIT([psmisc],[22.16])
 AC_CONFIG_SRCDIR([src/comm.h])
 AC_CONFIG_HEADER([config.h])
index 2b780b0e18d0f89305b065ad94a729f7f5892be8..f248a43ca3a2ac47c1ad6e1e2ba29d2eaa5e7481 100644 (file)
@@ -30,8 +30,7 @@
 /*
  * 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
+#define COMM_LEN 16
 
 #endif
index ed966d2bf8e8b474b6e87a91ef4579d534290ece..e4081ebb7832f5f30c195e0f762dc1a2d64942ae 100644 (file)
@@ -1783,9 +1783,10 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head,
  * Execute stat(2) system call with timeout to avoid deadlock
  * on network based file systems.
  */
+#ifdef HAVE_TIMEOUT_STAT
+
 static sigjmp_buf jenv;
 
-#ifdef HAVE_TIMEOUT_STAT
 static void
 sigalarm(int sig)
 {
index 3129f7636e6353b22f1de8f6f354471d02a9e480..183a96676f85eb1ddfb7a821eb5b55ec6a8c6dd2 100644 (file)
@@ -69,7 +69,7 @@ extern const char *__progname;
 #define        VT_HD        "w"
 
 typedef struct _proc {
-    char comm[COMM_LEN + 1];
+    char comm[COMM_LEN + 2 + 1]; /* add another 2 for thread brackets */
     char **argv;                /* only used : argv[0] is 1st arg; undef if argc < 1 */
     int argc;                        /* with -a   : number of arguments, -1 if swapped    */
     pid_t pid;
@@ -264,7 +264,8 @@ static PROC *new_proc(const char *comm, pid_t pid, uid_t uid)
         perror("malloc");
         exit(1);
     }
-    strncpy(new->comm, comm, COMM_LEN);
+    strncpy(new->comm, comm, COMM_LEN+2);
+       new->comm[COMM_LEN+2]='\0'; /* make sure nul terminated*/
     new->pid = pid;
     new->uid = uid;
     new->flags = 0;
@@ -352,7 +353,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 {
-        strncpy(this->comm, comm, COMM_LEN);
+        strncpy(this->comm, comm, COMM_LEN+2);
         this->uid = uid;
     }
     if (args)