[CRIU] Re: [PATCH] proc: Make sure eol remains on task name
Pavel Emelyanov
xemul at parallels.com
Thu May 3 05:02:59 EDT 2012
On 04/26/2012 09:43 PM, Cyrill Gorcunov wrote:
> It is not a problem at moment since we define
> TASK_COMM_LEN=16 exactly as defined in kernel,
> but things might change in future so better
> be on a safe side.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> proc_parse.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/proc_parse.c b/proc_parse.c
> index cd1e7d6..891c20c 100644
> --- a/proc_parse.c
> +++ b/proc_parse.c
> @@ -220,7 +220,7 @@ int parse_pid_stat_small(pid_t pid, struct proc_pid_stat_small *s)
> *tok = '\0';
> *p = '\0';
>
> - strncpy(s->comm, tok + 1, sizeof(s->comm));
> + strncpy(s->comm, tok + 1, sizeof(s->comm) - 1);
Better define the s->comm as an array of TASK_COMM_LEN + 1 to keep the ability
to read comms of maximal length.
> n = sscanf(p + 1, " %c %d %d %d", &s->state, &s->ppid, &s->pgid, &s->sid);
> if (n < 4)
> @@ -269,7 +269,7 @@ int parse_pid_stat(pid_t pid, struct proc_pid_stat *s)
> *tok = '\0';
> *p = '\0';
>
> - strncpy(s->comm, tok + 1, sizeof(s->comm));
> + strncpy(s->comm, tok + 1, sizeof(s->comm) - 1);
>
> n = sscanf(p + 1,
> " %c %d %d %d %d %d %u %lu %lu %lu %lu "
More information about the CRIU
mailing list