From f80694deed7bddbb85364247dc18f7df1a8fa88c Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 15 Jan 2012 20:24:13 +0400 Subject: [PATCH] proc_pase: Make sure we may scan up to 15 symbols in name And do not use strcpy, better to stick with strncpy. Moreover, to be on a safe side make proc internal buffer big enough even for "(%16s)" format, it's hardly possible that the kernel ever change stat format but just to be on a safe side. Signed-off-by: Cyrill Gorcunov --- cr-dump.c | 2 +- include/proc_parse.h | 6 +++--- proc_parse.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index 01eeca59a..05216a775 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -449,7 +449,7 @@ static int get_task_stat(pid_t pid, int pid_dir, u8 *comm, u32 *flags, if (ret < 0) goto err; - strcpy((char *)comm, pps_buf.comm); + strncpy((char *)comm, pps_buf.comm, TASK_COMM_LEN); *flags = pps_buf.flags; *start_code = pps_buf.start_code; *end_code = pps_buf.end_code; diff --git a/include/proc_parse.h b/include/proc_parse.h index e67568eaa..cd4218fee 100644 --- a/include/proc_parse.h +++ b/include/proc_parse.h @@ -1,12 +1,12 @@ #ifndef PROC_PARSE_H__ #define PROC_PARSE_H__ -#define TASK_COMM_LEN 16 -#define TASK_COMM_LEN_FMT "(%15s" +#define PROC_TASK_COMM_LEN 32 +#define PROC_TASK_COMM_LEN_FMT "(%31s" struct proc_pid_stat { int pid; - char comm[TASK_COMM_LEN]; + char comm[PROC_TASK_COMM_LEN]; char state; int ppid; int pgid; diff --git a/proc_parse.c b/proc_parse.c index d0297b81a..d621c96ad 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -188,7 +188,7 @@ int parse_pid_stat(pid_t pid, int pid_dir, struct proc_pid_stat *s) memset(s, 0, sizeof(*s)); n = fscanf(f, - "%d " TASK_COMM_LEN_FMT " %c %d %d %d %d %d %u %lu %lu %lu %lu " + "%d " PROC_TASK_COMM_LEN_FMT " %c %d %d %d %d %d %u %lu %lu %lu %lu " "%lu %lu %ld %ld %ld %ld %d %d %llu %lu %ld %lu %lu %lu %lu " "%lu %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld " "%lu %lu %lu", @@ -245,7 +245,7 @@ int parse_pid_stat(pid_t pid, int pid_dir, struct proc_pid_stat *s) return -1; } - s->comm[TASK_COMM_LEN-1] = '\0'; + s->comm[PROC_TASK_COMM_LEN-1] = '\0'; tok = strchr(s->comm, ')'); if (tok) *tok = '\0';