Re: [PATCH v4 2/6] string_helpers: add kstrdup_quotable_cmdline

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2016-04-12 at 16:19 -0500, Serge E. Hallyn wrote:
> Quoting Kees Cook (keescook@xxxxxxxxxxxx):
> > 
> > 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.shevchenko@xxxxxxxxxxxxxxx>
Intel Finland Oy

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



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux