lkml.org 
[lkml]   [2016]   [Apr]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 2/5] string_helpers: add kstrdup_quotable_cmdline
From
On Wed, Mar 30, 2016 at 4:11 AM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Wed, 2016-03-30 at 14:07 +0300, Andy Shevchenko wrote:
>> On Mon, 2016-03-28 at 14:14 -0700, Kees Cook wrote:
>
>
>> > + res = get_cmdline(task, buffer, PAGE_SIZE - 1);
>> > + buffer[res] = '\0';
>> > +
>> > + /* Collapse trailing NULLs. */
>> > + for (; res > 0; res--)
>> > + if (buffer[res-1] != '\0')
>> > + break;
>> /* buffer[res] is '\0', so, predecrement is safe here */
>> while (buffer[--res] == '\0')
>> /* nothing */;
>>
>> ?
>>
>
> Oops, no, the following should be better
>
> while (--res >= 0 && buffer[res] == '\0') ;

Sure, I'll change it. Though I'll need to adjust the next loop's use
of res (since it effectively changes from "number of bytes" counter to
"location of last non-null byte" (i <= res).

-Kees

--
Kees Cook
Chrome OS & Brillo Security

\
 
 \ /
  Last update: 2016-04-07 02:21    [W:0.229 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site