Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751351AbbDHGAg (ORCPT ); Wed, 8 Apr 2015 02:00:36 -0400 Received: from ozlabs.org ([103.22.144.67]:59764 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751132AbbDHGAf (ORCPT ); Wed, 8 Apr 2015 02:00:35 -0400 From: Rusty Russell To: Arthur Gautier Cc: linux-kernel@vger.kernel.org, Arthur Gautier Subject: Re: [PATCH] param: fixup quote parsing of kernel arguments In-Reply-To: <1428405635-8231-1-git-send-email-baloo@gandi.net> References: <1428405635-8231-1-git-send-email-baloo@gandi.net> User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Wed, 08 Apr 2015 15:29:43 +0930 Message-ID: <87twwr17ow.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2574 Lines: 104 Arthur Gautier writes: > When starting kernel with arguments like: > init=/bin/sh -c "echo arguments" > the trailing double quote is not removed which results in following command > being executed: > /bin/sh -c 'echo arguments"' > > This commit removes the trailing double quote. > > Signed-off-by: Arthur Gautier Hi Arthur, Thanks, I'd not considered quotes outside '='. But this fixes it in a weird way: we handle quotes below, we just don't do anything for the "raw value" case: for (i = 0; args[i]; i++) { if (isspace(args[i]) && !in_quote) break; if (equals == 0) { if (args[i] == '=') equals = i; } if (args[i] == '"') in_quote = !in_quote; } *param = args; if (!equals) *val = NULL; else { args[equals] = '\0'; *val = args + equals + 1; /* Don't include quotes in value. */ if (**val == '"') { (*val)++; if (args[i-1] == '"') args[i-1] = '\0'; } if (quoted && args[i-1] == '"') args[i-1] = '\0'; } The logical fix is to just always remove the close quotes in both cases: diff --git a/kernel/params.c b/kernel/params.c index 728e05b167de..a22d6a759b1a 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -173,9 +173,9 @@ static char *next_arg(char *args, char **param, char **val) if (args[i-1] == '"') args[i-1] = '\0'; } - if (quoted && args[i-1] == '"') - args[i-1] = '\0'; } + if (quoted && args[i-1] == '"') + args[i-1] = '\0'; if (args[i]) { args[i] = '\0'; Does this work for you? Thanks, Rusty. > --- > kernel/params.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/kernel/params.c b/kernel/params.c > index 728e05b..2118546 100644 > --- a/kernel/params.c > +++ b/kernel/params.c > @@ -156,8 +156,11 @@ static char *next_arg(char *args, char **param, char **val) > if (args[i] == '=') > equals = i; > } > - if (args[i] == '"') > + if (args[i] == '"') { > + if (!equals) > + args[i] = '\0'; > in_quote = !in_quote; > + } > } > > *param = args; > -- > 2.1.4 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/