Received: by 10.223.164.202 with SMTP id h10csp754329wrb; Wed, 15 Nov 2017 07:23:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMYOXdspT3vSWOKr7f15jyW08Rg7F8ATJoPyT5gzhtZcrIAppQJgUXXVGM47C3S01yKrFqk4 X-Received: by 10.101.100.216 with SMTP id t24mr15687970pgv.439.1510759399112; Wed, 15 Nov 2017 07:23:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510759399; cv=none; d=google.com; s=arc-20160816; b=OoGoR79rvXzdKqAvEKvMapGYjsNDrcyIQ/OBOiJuFSrd4l+c37u+QKvc6AjNaU8cLo hIyz4L4xpvxSIEz42oUsle/fFaDqP6vboIm6iXlfZaLMdJFVpre8aD2/GLUTOXFRulHR sIa0dNFDc4afN9EKYlB9z49J30UL7O/GeU2IC17LWs05zwZW7Wku7cl71hw+OIRIzv4S njv3KAcJCKZRNErR3wLhW96Us7nT+NMA6w00wnxYWpXeUXpGSEy9wMO15xPwaItes8Nv kcMmnE6KpHSPKLFBzZlw4sdOz335BdUNDP4Yh6Ye7aV9eTuQ03KpPF34odZZvXmjjFoM w2Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:user-agent:references:in-reply-to:date:cc:to:from :subject:arc-authentication-results; bh=+vGrxXqmEJkzefWpg4qWXQvGEhk9xWi5VpczCjIZXvU=; b=ZU+NsbWpj0znCb8ZB//HUmZ/vcX+dMDiNHQbk6BqOIVGefbOtfLxpQtMrvFfnZeTqH ogVsbIFDa/HRSeMJUbKLoYGp6TdMVAthVXA1O5Sas7XQ9vuFxiNrVgDshfRb8rq5Iqf6 uGuGJquI5RIJh+YL/tRLv46ceSBEXCxyb5NGzS5VREKV79PUqQF/IT+EuMWBhxw5iq7a Kl9E/sfNsvbSFByPw9ogiOstYVhfvvSK2j7A506EHuAt6h1RHWQFo+XWuOQoQQr28CcJ Lrw7UJnDk/AWXogmltYJQwCAQN+SsyfbVwuGFUsWg+CvwfuevBej7VwLztVW25DoYIKW 7E+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y13si16292144pgs.580.2017.11.15.07.23.05; Wed, 15 Nov 2017 07:23:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758568AbdKOPRs (ORCPT + 89 others); Wed, 15 Nov 2017 10:17:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39578 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757491AbdKOPRg (ORCPT ); Wed, 15 Nov 2017 10:17:36 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAFFHRl6075079 for ; Wed, 15 Nov 2017 10:17:36 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e8r1dgbgg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 15 Nov 2017 10:17:36 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 Nov 2017 15:17:33 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 15 Nov 2017 15:17:29 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAFFHTVW50135140; Wed, 15 Nov 2017 15:17:29 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3288352047; Wed, 15 Nov 2017 14:11:10 +0000 (GMT) Received: from hbathini.in.ibm.com (unknown [9.79.199.182]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id DFC0E5203F; Wed, 15 Nov 2017 14:11:07 +0000 (GMT) Subject: [PATCH v9 3/8] lib/cmdline.c: add backslash support to kernel commandline parsing From: Hari Bathini To: linuxppc-dev , Andrew Morton , lkml Cc: Michael Ellerman , Ankit Kumar , Michal =?utf-8?b?U3VjaMOhbmVr?= , Mahesh J Salgaonkar Date: Wed, 15 Nov 2017 20:47:25 +0530 In-Reply-To: <151075897205.14434.9005256552409420263.stgit@hbathini.in.ibm.com> References: <151075897205.14434.9005256552409420263.stgit@hbathini.in.ibm.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 17111515-0016-0000-0000-00000501A6DE X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111515-0017-0000-0000-0000283D6230 Message-Id: <151075904367.14434.5164139208561977016.stgit@hbathini.in.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-15_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711150206 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michal Suchanek This allows passing quotes in kernel arguments. It is useful for passing nested arguemnts and might be useful if somebody wanted to pass a double quote directly as part of an argument. It is also useful to have quoting grammar more similar to shells and bootloaders. Signed-off-by: Michal Suchanek Signed-off-by: Hari Bathini --- lib/cmdline.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index 6d398a8..d98bdc0 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -193,30 +193,36 @@ bool parse_option_str(const char *str, const char *option) /* * Parse a string to get a param value pair. - * You can use " around spaces, but can't escape ". + * You can use " around spaces, and you can escape with \ * Hyphens and underscores equivalent in parameter names. */ char *next_arg(char *args, char **param, char **val) { unsigned int i, equals = 0; - int in_quote = 0, quoted = 0; + int in_quote = 0, backslash = 0; char *next; - if (*args == '"') { - args++; - in_quote = 1; - quoted = 1; - } - for (i = 0; args[i]; i++) { - if (isspace(args[i]) && !in_quote) + if (isspace(args[i]) && !in_quote && !backslash) break; - if (equals == 0) { - if (args[i] == '=') - equals = i; + + if ((equals == 0) && (args[i] == '=')) + equals = i; + + if (!backslash) { + if ((args[i] == '"') || (args[i] == '\\')) { + if (args[i] == '"') + in_quote = !in_quote; + if (args[i] == '\\') + backslash = 1; + + memmove(args + 1, args, i); + args++; + i--; + } + } else { + backslash = 0; } - if (args[i] == '"') - in_quote = !in_quote; } *param = args; @@ -225,13 +231,6 @@ char *next_arg(char *args, char **param, char **val) else { args[equals] = '\0'; *val = args + equals + 1; - - /* Don't include quotes in value. */ - if ((args[i-1] == '"') && ((quoted) || (**val == '"'))) { - args[i-1] = '\0'; - if (!quoted) - (*val)++; - } } if (args[i]) { From 1584150090996393690@xxx Wed Nov 15 16:27:35 +0000 2017 X-GM-THRID: 1584150090996393690 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread