Linux Device Mapper development
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Christophe Varoqui <christophe.varoqui@opensvc.com>
Cc: dm-devel@redhat.com, Martin Wilck <mwilck@suse.com>
Subject: [PATCH v2 3/5] libmultipath: config parser: Allow '"' in strings
Date: Thu,  8 Mar 2018 00:26:18 +0100	[thread overview]
Message-ID: <20180307232620.15746-4-mwilck@suse.com> (raw)
In-Reply-To: <20180307232620.15746-1-mwilck@suse.com>

We have seen model strings lile '2.5" SSD' which can't be parsed
by the current config parser. This patch fixes this by allowing
'""' to represent a double quote character inside a a string.
The above model string could now be entered in the config file like this:

blacklist {
	  vendor SomeCorp
	  product "2.5"" SSD"
}

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/parser.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 3d9656f47945..21151a16ad74 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -219,11 +219,13 @@ alloc_strvec(char *string)
 
 	in_string = 0;
 	while (1) {
+		int two_quotes = 0;
+
 		if (!vector_alloc_slot(strvec))
 			goto out;
 
 		start = cp;
-		if (*cp == '"') {
+		if (*cp == '"' && !(in_string && *(cp + 1) == '"')) {
 			cp++;
 			token = MALLOC(2);
 
@@ -246,11 +248,23 @@ alloc_strvec(char *string)
 			*(token + 1) = '\0';
 			cp++;
 		} else {
+
+		move_on:
 			while ((in_string ||
 				(!isspace((int) *cp) && isascii((int) *cp) &&
 				 *cp != '!' && *cp != '#' && *cp != '{' &&
 				 *cp != '}')) && *cp != '\0' && *cp != '"')
 				cp++;
+
+			/* Two consecutive double quotes - don't end string */
+			if (in_string && *cp == '"') {
+				if (*(cp + 1) == '"') {
+					two_quotes = 1;
+					cp += 2;
+					goto move_on;
+				}
+			}
+
 			strlen = cp - start;
 			token = MALLOC(strlen + 1);
 
@@ -259,6 +273,16 @@ alloc_strvec(char *string)
 
 			memcpy(token, start, strlen);
 			*(token + strlen) = '\0';
+
+			/* Replace "" by " */
+			if (two_quotes) {
+				char *qq = strstr(token, "\"\"");
+				while (qq != NULL) {
+					memmove(qq + 1, qq + 2,
+						strlen + 1 - (qq + 2 - token));
+					qq = strstr(qq + 1, "\"\"");
+				}
+			}
 		}
 		vector_set_slot(strvec, token);
 
-- 
2.16.1

  parent reply	other threads:[~2018-03-07 23:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 23:26 [PATCH v2 0/5] Fixes for config file parsing Martin Wilck
2018-03-07 23:26 ` [PATCH v2 1/5] tests: add unit tests for config file parser Martin Wilck
2018-03-07 23:26 ` [PATCH v2 2/5] libmultipath: config parser: don't strip whitepace between quotes Martin Wilck
2018-03-07 23:26 ` Martin Wilck [this message]
2018-03-23 16:59   ` [PATCH v2 3/5] libmultipath: config parser: Allow '"' in strings Xose Vazquez Perez
2018-03-23 17:40     ` Martin Wilck
2018-03-07 23:26 ` [PATCH v2 4/5] libmultipath: config parser: fix corner case for double quotes Martin Wilck
2018-03-07 23:26 ` [PATCH v2 5/5] multipath.conf(5): improve syntax documentation Martin Wilck
2018-03-14 17:41 ` [PATCH v2 0/5] Fixes for config file parsing Benjamin Marzinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180307232620.15746-4-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox