Received: by 10.223.164.202 with SMTP id h10csp854420wrb; Wed, 15 Nov 2017 08:59:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMaX7YZTa0DCn5vZ+/ga/3CYDJJsHqBHOE6As8ePvMYFj2I9nxOvGRiTM/lUvN03Tdrr8PyC X-Received: by 10.159.194.1 with SMTP id x1mr2502824pln.235.1510765183393; Wed, 15 Nov 2017 08:59:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510765183; cv=none; d=google.com; s=arc-20160816; b=IMXZWRyix2aIrxqJSNtEaAQBmRK6MBPBOPIrlmOXAVKm3Lf5D/7hUC1KW2Z1+i8RXi TpgVIvN/KcmrlbNoihGiN8l1qP0Z1y2pjT//pF3bZeaVe6j/K7qILsEn4RZVG0Kfh+vf T5NOZDbkwzJY9HtUWdyiR5fWK2xwSjMIrlWOPPZajLOXnduqw3QzZKZeIARBqKhM1hzO VTaysUSgFmOX0jc3QPUH3Erg9NvkiteS2tKkGENT2FBxNJ7FEjsJEDkQ1w2MFAP5wK0u koSg/WHTlWuXoDe5KmaL5YXUOuMw8l6bjeMBzmuNMFKvfTxL+M58Rx5rFPBbJuMc05FO oOog== 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=hkbPFY+cWQNdu3mxWdilODCaXNkED5U8pUb1bw9p9FE=; b=gf+imNsm8gx4T/HNpuPmTKVa7KO7wI+soa9+TaFpauQN67sPyafOCaVWvk1aJ87sIR pn2Pvv0UHO314c0+IOp9SEasOlrNv9pbLproA97jCJp0p8mKF7ZkFLl9N34ptzFUbe76 FEEc17xVD1Ft1w6urd2wxl5Cq0ojDUWZy4cVXEI4Jb9WXrnGAbHzdYijZOJo9w8knf17 +UyZoM1N1y6/HjhHS1bFxI3NvShXD4RNUtK/551ISPOSgEaU52uyho1bqnYPjYByHQbj Zy8v4Qwuzx3plRoCZDPDVVxkkFu27gM0Uk74YiRGCaTw/FdXkbmQXx3TgH4OmHGpudly 2RAw== 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 9si18101658ple.631.2017.11.15.08.59.30; Wed, 15 Nov 2017 08:59:43 -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 S1758613AbdKOPSm (ORCPT + 89 others); Wed, 15 Nov 2017 10:18:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58866 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758554AbdKOPSe (ORCPT ); Wed, 15 Nov 2017 10:18:34 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAFFFrPF105968 for ; Wed, 15 Nov 2017 10:18:34 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e8qjdt711-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 15 Nov 2017 10:18:33 -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:18:31 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) 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:18:29 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAFFITb733488910; Wed, 15 Nov 2017 15:18:29 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 714A04C05C; Wed, 15 Nov 2017 15:13:42 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1F48B4C062; Wed, 15 Nov 2017 15:13:40 +0000 (GMT) Received: from hbathini.in.ibm.com (unknown [9.79.199.182]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 15 Nov 2017 15:13:39 +0000 (GMT) Subject: [PATCH v9 5/8] lib/cmdline.c: implement single quotes in commandline argument 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:48: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-00000501A6F7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111515-0017-0000-0000-0000283D624C Message-Id: <151075906562.14434.17655499193254963975.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 brings the kernel parser about on par with bourne shell, grub, and other tools that chew the arguments before kernel does. This should make it easier to deal with multiple levels of nesting/quoting. With same quoting grammar on each level there is less room for confusion. Signed-off-by: Michal Suchanek --- lib/cmdline.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/cmdline.c b/lib/cmdline.c index d98bdc0..c5335a7 100644 --- a/lib/cmdline.c +++ b/lib/cmdline.c @@ -191,34 +191,45 @@ bool parse_option_str(const char *str, const char *option) return false; } +#define squash_char { \ + memmove(args + 1, args, i); \ + args++; \ + i--; \ +} + /* * Parse a string to get a param value pair. - * You can use " around spaces, and you can escape with \ + * You can use " or ' 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, backslash = 0; + int in_quote = 0, backslash = 0, in_single = 0; char *next; for (i = 0; args[i]; i++) { - if (isspace(args[i]) && !in_quote && !backslash) + if (isspace(args[i]) && !in_quote && !backslash && !in_single) break; if ((equals == 0) && (args[i] == '=')) equals = i; - if (!backslash) { - if ((args[i] == '"') || (args[i] == '\\')) { + if (in_single) { + if (args[i] == '\'') { + in_single = 0; + squash_char; + } + } else if (!backslash) { + if ((args[i] == '"') || (args[i] == '\\') || + (args[i] == '\'')) { if (args[i] == '"') in_quote = !in_quote; if (args[i] == '\\') backslash = 1; - - memmove(args + 1, args, i); - args++; - i--; + if (args[i] == '\'') + in_single = 1; + squash_char; } } else { backslash = 0; From 1583482865510504420@xxx Wed Nov 08 07:42:19 +0000 2017 X-GM-THRID: 1582925127753096862 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread