From patchwork Tue Mar 6 22:56:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10263101 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6FA9C60211 for ; Tue, 6 Mar 2018 23:21:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63BA928716 for ; Tue, 6 Mar 2018 23:21:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 581952921D; Tue, 6 Mar 2018 23:21:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A0BDB28716 for ; Tue, 6 Mar 2018 23:21:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6F2781DE8; Tue, 6 Mar 2018 23:21:04 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBF3E5D962; Tue, 6 Mar 2018 23:21:03 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 521214A46D; Tue, 6 Mar 2018 23:21:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w26NL14f032011 for ; Tue, 6 Mar 2018 18:21:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4528B5D962; Tue, 6 Mar 2018 23:21:01 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4E445D9CA; Tue, 6 Mar 2018 23:20:57 +0000 (UTC) Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EE3D25F7B8; Tue, 6 Mar 2018 23:20:55 +0000 (UTC) Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Wed, 07 Mar 2018 00:20:54 +0100 Received: from apollon.suse.de.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (TLS encrypted); Tue, 06 Mar 2018 22:57:14 +0000 From: Martin Wilck To: Christophe Varoqui Date: Tue, 6 Mar 2018 23:56:32 +0100 Message-Id: <20180306225633.12028-6-mwilck@suse.com> In-Reply-To: <20180306225633.12028-1-mwilck@suse.com> References: <20180306225633.12028-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 06 Mar 2018 23:20:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 06 Mar 2018 23:20:56 +0000 (UTC) for IP:'195.135.221.5' DOMAIN:'smtp.nue.novell.com' HELO:'smtp.nue.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 195.135.221.5 smtp.nue.novell.com 195.135.221.5 smtp.nue.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Xose Vazquez Perez , dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 5/6] libmultipath: config parser: fix corner case for double quotes X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 06 Mar 2018 23:21:05 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP A corner case of the previous patch are strings starting with a double quote, such as '"prepended to itself is false" prepended to itself is false' or '"" is the empty string', and in particular, the string '"' ("\"" in C notation), which is indistinguishable from the "QUOTE" token in the parsed strvec. This patch fixes that by introducing a special token that can't occur as part of a normal string to indicate the beginning and end of a quoted string. '"' is admittedly not a very likely keyword value for multipath.conf, but a) this is a matter of correctness, b) we didn't think of '2.5"' before, either, and c) the (*str != '"') expressions would need to be patched anyway to fix the 'string starting with "' case. Signed-off-by: Martin Wilck --- libmultipath/parser.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index 592269a9b5b1..da8de305f680 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -186,6 +186,12 @@ snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw, return fwd; } +static const char quote_marker[] = { '\0', '"', '\0' }; +static bool is_quote(const char* token) +{ + return !memcmp(token, quote_marker, sizeof(quote_marker)); +} + vector alloc_strvec(char *string) { @@ -225,17 +231,13 @@ alloc_strvec(char *string) start = cp; if (!in_string && *cp == '"') { cp++; - token = MALLOC(2); + token = MALLOC(sizeof(quote_marker)); if (!token) goto out; - *(token) = '"'; - *(token + 1) = '\0'; - if (in_string) - in_string = 0; - else - in_string = 1; + memcpy(token, quote_marker, sizeof(quote_marker)); + in_string = 1; } else if (!in_string && (*cp == '{' || *cp == '}')) { token = MALLOC(2); @@ -324,13 +326,13 @@ set_value(vector strvec) (char *)VECTOR_SLOT(strvec, 0)); return NULL; } - size = strlen(str); - if (size == 0) { - condlog(0, "option '%s' has empty value", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; - } - if (*str != '"') { + if (!is_quote(str)) { + size = strlen(str); + if (size == 0) { + condlog(0, "option '%s' has empty value", + (char *)VECTOR_SLOT(strvec, 0)); + return NULL; + } alloc = MALLOC(sizeof (char) * (size + 1)); if (alloc) memcpy(alloc, str, size); @@ -354,7 +356,7 @@ set_value(vector strvec) (char *)VECTOR_SLOT(strvec, 0)); return NULL; } - if (*str == '"') + if (is_quote(str)) break; tmp = alloc; /* The first +1 is for the NULL byte. The rest are for the @@ -460,7 +462,7 @@ validate_config_strvec(vector strvec, char *file) (char *)VECTOR_SLOT(strvec, 0), line_nr, file); return -1; } - if (*str != '"') { + if (!is_quote(str)) { if (VECTOR_SIZE(strvec) > 2) condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, 2), line_nr, file); return 0; @@ -472,7 +474,7 @@ validate_config_strvec(vector strvec, char *file) line_nr, file); return -1; } - if (*str == '"') { + if (is_quote(str)) { if (VECTOR_SIZE(strvec) > i + 1) condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, (i + 1)), line_nr, file); return 0;