mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-28 21:07:43 +00:00
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 <gorcunov@openvz.org>
This commit is contained in:
parent
a9969dcf72
commit
f80694deed
@ -449,7 +449,7 @@ static int get_task_stat(pid_t pid, int pid_dir, u8 *comm, u32 *flags,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
strcpy((char *)comm, pps_buf.comm);
|
strncpy((char *)comm, pps_buf.comm, TASK_COMM_LEN);
|
||||||
*flags = pps_buf.flags;
|
*flags = pps_buf.flags;
|
||||||
*start_code = pps_buf.start_code;
|
*start_code = pps_buf.start_code;
|
||||||
*end_code = pps_buf.end_code;
|
*end_code = pps_buf.end_code;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef PROC_PARSE_H__
|
#ifndef PROC_PARSE_H__
|
||||||
#define PROC_PARSE_H__
|
#define PROC_PARSE_H__
|
||||||
|
|
||||||
#define TASK_COMM_LEN 16
|
#define PROC_TASK_COMM_LEN 32
|
||||||
#define TASK_COMM_LEN_FMT "(%15s"
|
#define PROC_TASK_COMM_LEN_FMT "(%31s"
|
||||||
|
|
||||||
struct proc_pid_stat {
|
struct proc_pid_stat {
|
||||||
int pid;
|
int pid;
|
||||||
char comm[TASK_COMM_LEN];
|
char comm[PROC_TASK_COMM_LEN];
|
||||||
char state;
|
char state;
|
||||||
int ppid;
|
int ppid;
|
||||||
int pgid;
|
int pgid;
|
||||||
|
@ -188,7 +188,7 @@ int parse_pid_stat(pid_t pid, int pid_dir, struct proc_pid_stat *s)
|
|||||||
|
|
||||||
memset(s, 0, sizeof(*s));
|
memset(s, 0, sizeof(*s));
|
||||||
n = fscanf(f,
|
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 %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 %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld "
|
||||||
"%lu %lu %lu",
|
"%lu %lu %lu",
|
||||||
@ -245,7 +245,7 @@ int parse_pid_stat(pid_t pid, int pid_dir, struct proc_pid_stat *s)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->comm[TASK_COMM_LEN-1] = '\0';
|
s->comm[PROC_TASK_COMM_LEN-1] = '\0';
|
||||||
tok = strchr(s->comm, ')');
|
tok = strchr(s->comm, ')');
|
||||||
if (tok)
|
if (tok)
|
||||||
*tok = '\0';
|
*tok = '\0';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user