From patchwork Wed Nov 15 15:18:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hari Bathini X-Patchwork-Id: 838222 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ycSsY6P7Mz9sBW for ; Thu, 16 Nov 2017 02:26:57 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3ycSsY5Jd5zDr1w for ; Thu, 16 Nov 2017 02:26:57 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3ycSgw6q26zDql8 for ; Thu, 16 Nov 2017 02:18:36 +1100 (AEDT) Received: from ozlabs.org (bilbo.ozlabs.org [103.22.144.67]) by bilbo.ozlabs.org (Postfix) with ESMTP id 3ycSgw3r2mz8t1V for ; Thu, 16 Nov 2017 02:18:36 +1100 (AEDT) Received: by ozlabs.org (Postfix) id 3ycSgw38yYz9sBZ; Thu, 16 Nov 2017 02:18:36 +1100 (AEDT) Delivered-To: linuxppc-dev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=hbathini@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ycSgv67shz9s7C for ; Thu, 16 Nov 2017 02:18:35 +1100 (AEDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAFFFXGP127569 for ; Wed, 15 Nov 2017 10:18:33 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e8qqhhm01-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 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 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 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michal =?utf-8?b?U3VjaMOhbmVr?= , Ankit Kumar , Mahesh J Salgaonkar Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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;