lkml.org 
[lkml]   [2021]   [Oct]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v4 2/5] connector: use __get_task_comm in proc_comm_connector
On Thu, Oct 14, 2021 at 10:24 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Thu, 14 Oct 2021 09:48:09 +0800
> Yafang Shao <laoar.shao@gmail.com> wrote:
>
> > > __get_task_comm() uses strncpy() which my understanding is, does not add
> > > the nul terminating byte when truncating. Which changes the functionality
> > > here. As all task comms have a terminating byte, the old method would copy
> > > that and include it. This won't add the terminating byte if the buffer is
> > > smaller than the comm, and that might cause issues.
> > >
> >
> > Right, that is a problem.
> > It seems that we should add a new helper get_task_comm_may_truncated().
>
> Or simply change __get_task_comm() to:
>
> char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk)
> {
> task_lock(tsk);
> strncpy(buf, tsk->comm, buf_size);
> /* The copied value is always nul terminated */
> buf[buf_size - 1] = '\0';
> task_unlock(tsk);
> return buf;
> }
>

That is better! Thanks for the suggestion.

> But that should probably be a separate patch.
>

Sure.

--
Thanks
Yafang

\
 
 \ /
  Last update: 2021-10-14 04:43    [W:0.088 / U:0.068 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site