From patchwork Tue Jun 9 21:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 11596645 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 145BF92A for ; Tue, 9 Jun 2020 21:36:56 +0000 (UTC) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1EE320734 for ; Tue, 9 Jun 2020 21:36:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iuFXL2Ac" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1EE320734 Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591738614; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JJPqcJ+R5b4x2AHg6pH2p/ViICc2vVxcqhID+kvVCHE=; b=iuFXL2AcNqEHkkjzTW+lMwclsejh6x17XhyiDdUDaPfPWs5vMLcl6w4kXmMZHWffirbby2 qRRqLMB9Pust/Y+GGgf9iB1e50ccRIeqKwVRsrVC9C7F/hCgUoBSuMk2GVMoN1o8xzEUZn rwe7712KgIc93KdQloiNZZtsH5Drr7U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-GMCRF1FGNueyIZbfOp1X3Q-1; Tue, 09 Jun 2020 17:36:51 -0400 X-MC-Unique: GMCRF1FGNueyIZbfOp1X3Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5EC581883605; Tue, 9 Jun 2020 21:36:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 442AD7F0BE; Tue, 9 Jun 2020 21:36:47 +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 1B2631809554; Tue, 9 Jun 2020 21:36:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 059LZcDe029302 for ; Tue, 9 Jun 2020 17:35:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id EF47219D61; Tue, 9 Jun 2020 21:35:38 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from octiron.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 28EF719C71; Tue, 9 Jun 2020 21:35:36 +0000 (UTC) Received: from octiron.msp.redhat.com (localhost.localdomain [127.0.0.1]) by octiron.msp.redhat.com (8.14.9/8.14.9) with ESMTP id 059LZYG3026854; Tue, 9 Jun 2020 16:35:34 -0500 Received: (from bmarzins@localhost) by octiron.msp.redhat.com (8.14.9/8.14.9/Submit) id 059LZYE0026853; Tue, 9 Jun 2020 16:35:34 -0500 From: Benjamin Marzinski To: Christophe Varoqui Date: Tue, 9 Jun 2020 16:35:28 -0500 Message-Id: <1591738529-26810-3-git-send-email-bmarzins@redhat.com> In-Reply-To: <1591738529-26810-1-git-send-email-bmarzins@redhat.com> References: <1591738529-26810-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: device-mapper development , Nikhil Kshirsagar , Martin Wilck Subject: [dm-devel] [PATCH v2 2/3] libmultipath: fix parser issue with comments in strings 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.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com If a quoted string starts with '#' or '!', the parser will stop parsing the line, thinking that it's a comment. It should only be checking for comments outside of quoted strings. Fixed this and added unit tests to verify it. Signed-off-by: Benjamin Marzinski --- libmultipath/parser.c | 4 +++- tests/parser.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libmultipath/parser.c b/libmultipath/parser.c index d478b177..11a6168c 100644 --- a/libmultipath/parser.c +++ b/libmultipath/parser.c @@ -300,8 +300,10 @@ alloc_strvec(char *string) (isspace((int) *cp) || !isascii((int) *cp))) && *cp != '\0') cp++; - if (*cp == '\0' || *cp == '!' || *cp == '#') + if (*cp == '\0' || + (!in_string && (*cp == '!' || *cp == '#'))) { return strvec; + } } out: vector_free(strvec); diff --git a/tests/parser.c b/tests/parser.c index 29859dac..5772391e 100644 --- a/tests/parser.c +++ b/tests/parser.c @@ -440,6 +440,46 @@ static void test18(void **state) free_strvec(v); } +static void test19(void **state) +{ +#define QUOTED19 "!value" + vector v = alloc_strvec("key \"" QUOTED19 "\""); + char *val; + + assert_int_equal(VECTOR_SIZE(v), 4); + assert_string_equal(VECTOR_SLOT(v, 0), "key"); + assert_true(is_quote(VECTOR_SLOT(v, 1))); + assert_string_equal(VECTOR_SLOT(v, 2), QUOTED19); + assert_true(is_quote(VECTOR_SLOT(v, 3))); + assert_int_equal(validate_config_strvec(v, test_file), 0); + + val = set_value(v); + assert_string_equal(val, QUOTED19); + + free(val); + free_strvec(v); +} + +static void test20(void **state) +{ +#define QUOTED20 "#value" + vector v = alloc_strvec("key \"" QUOTED20 "\""); + char *val; + + assert_int_equal(VECTOR_SIZE(v), 4); + assert_string_equal(VECTOR_SLOT(v, 0), "key"); + assert_true(is_quote(VECTOR_SLOT(v, 1))); + assert_string_equal(VECTOR_SLOT(v, 2), QUOTED20); + assert_true(is_quote(VECTOR_SLOT(v, 3))); + assert_int_equal(validate_config_strvec(v, test_file), 0); + + val = set_value(v); + assert_string_equal(val, QUOTED20); + + free(val); + free_strvec(v); +} + int test_config_parser(void) { const struct CMUnitTest tests[] = { @@ -461,6 +501,8 @@ int test_config_parser(void) cmocka_unit_test(test16), cmocka_unit_test(test17), cmocka_unit_test(test18), + cmocka_unit_test(test19), + cmocka_unit_test(test20), }; return cmocka_run_group_tests(tests, setup, teardown); }