Messages in this thread | | | Subject | Re: [PATCH 1/5] x86: fix early command-line parsing when matching at end | From | Dave Hansen <> | Date | Wed, 6 Jan 2016 09:57:08 -0800 |
| |
Moving over to the actual patch we're talking about...
On 12/22/2015 02:52 PM, Dave Hansen wrote: > @@ -37,11 +39,14 @@ int cmdline_find_option_bool(const char > if (!cmdline) > return -1; /* No command line */ > > - len = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE); > - if (!len) > + if (!strlen(cmdline)) > return 0; > > - while (len--) { > + /* > + * This 'pos' check ensures we do not overrun > + * a non-NULL-terminated 'cmdline' > + */ > + while (pos < COMMAND_LINE_SIZE) {
Borislav says: >> So why not leave the min_t: >> >> maxlen = min_t(int, strlen(cmdline), COMMAND_LINE_SIZE); >> >> and then do: >> >> while (pos < maxlen)
That works, and it's functionally equivalent to what I have (I think). I like what I have because it separates the 'strlen' checking from the COMMAND_LINE_SIZE checking, which makes it super duper obvious that the third patch here is OK.
So, after the third patch, the strlen() goes away any way you do this. The code ends up looking the same (the while() check is against the max-length variable alone).
I'm happy to rewrite this to have a different intermediate form and repost the thing, but the end result will be the same.
| |