From: Craig Small Date: Thu, 9 Feb 2012 20:03:34 +0000 (+1100) Subject: Better comm_len fix X-Git-Tag: v22.16~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a3fb35da4bd714bce86c4f5ced344cff1c9ef45;p=psmisc Better comm_len fix 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. --- diff --git a/configure.ac b/configure.ac index e7e86fb..0615f5f 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/src/comm.h b/src/comm.h index 2b780b0..f248a43 100644 --- a/src/comm.h +++ b/src/comm.h @@ -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 diff --git a/src/fuser.c b/src/fuser.c index ed966d2..e4081eb 100644 --- a/src/fuser.c +++ b/src/fuser.c @@ -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) { diff --git a/src/pstree.c b/src/pstree.c index 3129f76..183a966 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -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)