On Tue, 2016-04-12 at 16:19 -0500, Serge E. Hallyn wrote:
> Quoting Kees Cook (keesc...@chromium.org):
> > 
> > Provide an escaped (but readable: no inter-argument NULLs)
> > commandline
> > safe for logging.
> > 

Sorry, have no access to the original mail right now.

>> +char *kstrdup_quotable_cmdline(struct task_struct *task, gfp_t gfp)
> > +{
> > +   char *buffer, *quoted;
> > +   int i, res;
> > +
> > +   buffer = kmalloc(PAGE_SIZE, GFP_TEMPORARY);
> > +   if (!buffer)
> > +           return NULL;
> > +
> > +   res = get_cmdline(task, buffer, PAGE_SIZE - 1);
> > +   buffer[res] = '\0';
> > +
> > +   /* Collapse trailing NULLs, leave res pointing to last non-
> > NULL. */
> > +   while (--res >= 0 && buffer[res] == '\0')
> > +           ;

Nitpick: perhaps leave comment that make more visible
/* nothing */ ;

(up to you)?

> > +
> > +   /* Replace inter-argument NULLs. */
> > +   for (i = 0; i <= res; i++)

But why do you need to check = res? It's already checked by previous
condition and undoubtfully it's non-'\0'.

Forgot to mention this earlier.

> > +           if (buffer[i] == '\0')
> > +                   buffer[i] = ' ';

-- 
Andy Shevchenko <andriy.shevche...@linux.intel.com>
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to