From: Craig Small Date: Sun, 26 Feb 2012 04:18:42 +0000 (+1100) Subject: Null terminate some strings X-Git-Tag: v22.16~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1aa34c3cc0299f5e7aeaeb4c710442b0f669a6e;p=psmisc Null terminate some strings --- diff --git a/ChangeLog b/ChangeLog index cf95c4b..45f6c04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ Changes in 22.16 ================ * Use strncpy for COMM_LEN and make it 18 characters to cover brackets in name. + * don't change COMM_LEN, it breaks matching long commands + Debian #661145 * Enable some harden AM_CFLAGS by default, use configure option --disable-harden-flags to not use it. diff --git a/src/killall.c b/src/killall.c index f108c77..da26237 100644 --- a/src/killall.c +++ b/src/killall.c @@ -768,12 +768,14 @@ main (int argc, char **argv) case 'y': NOT_PIDOF_OPTION; strncpy(yt, optarg, 16); + yt[15] = '\0'; if ( 0 >= (younger_than = parse_time_units(yt) ) ) usage(_("Invalid time format")); break; case 'o': NOT_PIDOF_OPTION; strncpy(ot, optarg, 16); + ot[15] = '\0'; if ( 0 >= (older_than = parse_time_units(ot) ) ) usage(_("Invalid time format")); break; diff --git a/src/pstree.c b/src/pstree.c index 183a966..80cfcec 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -265,7 +265,7 @@ static PROC *new_proc(const char *comm, pid_t pid, uid_t uid) exit(1); } strncpy(new->comm, comm, COMM_LEN+2); - new->comm[COMM_LEN+2]='\0'; /* make sure nul terminated*/ + new->comm[COMM_LEN+1]='\0'; /* make sure nul terminated*/ new->pid = pid; new->uid = uid; new->flags = 0; @@ -354,6 +354,7 @@ add_proc(const char *comm, pid_t pid, pid_t ppid, uid_t uid, #endif /*WITH_SELINUX */ else { strncpy(this->comm, comm, COMM_LEN+2); + this->comm[COMM_LEN+1]; this->uid = uid; } if (args)