From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752055AbcAFR5L (ORCPT ); Wed, 6 Jan 2016 12:57:11 -0500 Received: from www.sr71.net ([198.145.64.142]:36363 "EHLO blackbird.sr71.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751653AbcAFR5J (ORCPT ); Wed, 6 Jan 2016 12:57:09 -0500 Subject: Re: [PATCH 1/5] x86: fix early command-line parsing when matching at end To: x86@kernel.org References: <20151222225237.08CDE5F1@viggo.jf.intel.com> <20151222225238.9AEB560C@viggo.jf.intel.com> Cc: linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, bp@suse.de, hpa@zytor.com, fenghua.yu@intel.com, yu-cheng.yu@intel.com From: Dave Hansen Message-ID: <568D5574.2000006@sr71.net> Date: Wed, 6 Jan 2016 09:57:08 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <20151222225238.9AEB560C@viggo.jf.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.