From patchwork Wed Dec 14 21:38:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13073593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ABD8EC4332F for ; Wed, 14 Dec 2022 21:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671053940; 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=waWaNFyuBv2bE0I8emRLfkB/nruVui+d2PBbLv1MzMA=; b=ZXWqbJkX2LViOtvJHM/W/AAmRoDdW50s6ot2BzypuIwlE2PFM/E6JEWwJkQh5NAF72R2xs dAxMqbxVyOZ8G0gXwB8LQHSyF6JPm6Wc+t8+9xfBwaLpeEzZRgF09e9OGWaz/MGY4SmU1D 2iRCXl59FKpUrpgTuSi+cr+9TbZLghE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-665-rNPebR6gN9-aF-JHvqZcDQ-1; Wed, 14 Dec 2022 16:38:57 -0500 X-MC-Unique: rNPebR6gN9-aF-JHvqZcDQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27920802BF3; Wed, 14 Dec 2022 21:38:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 979352166B26; Wed, 14 Dec 2022 21:38:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 610651946A41; Wed, 14 Dec 2022 21:38:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6B41D1946A43 for ; Wed, 14 Dec 2022 21:38:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6C70B2026D2B; Wed, 14 Dec 2022 21:38:24 +0000 (UTC) Received: from octiron.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A5712026D76; Wed, 14 Dec 2022 21:38:24 +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 2BELcNYg014963; Wed, 14 Dec 2022 15:38:23 -0600 Received: (from bmarzins@localhost) by octiron.msp.redhat.com (8.14.9/8.14.9/Submit) id 2BELcM15014962; Wed, 14 Dec 2022 15:38:22 -0600 From: Benjamin Marzinski To: Christophe Varoqui Date: Wed, 14 Dec 2022 15:38:18 -0600 Message-Id: <1671053900-14923-2-git-send-email-bmarzins@redhat.com> In-Reply-To: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> References: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Subject: [dm-devel] [PATCH V2 1/3] libmpathutil: simplify set_value and validate_config_strvec X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: device-mapper development , Martin Wilck MIME-Version: 1.0 Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com alloc_strvec() will never create a strvec with multiple tokens between the quote tokens. Verify this in validate_config_strvec(), and simplify set_value() by only reading one value after a quote token. Signed-off-by: Benjamin Marzinski --- libmpathutil/parser.c | 109 ++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c index 8d3ac53a..29b212ce 100644 --- a/libmpathutil/parser.c +++ b/libmpathutil/parser.c @@ -333,59 +333,33 @@ void * set_value(vector strvec) { char *str = VECTOR_SLOT(strvec, 1); - size_t size; - int i = 0; - int len = 0; char *alloc = NULL; - char *tmp; if (!str) { condlog(0, "option '%s' missing value", (char *)VECTOR_SLOT(strvec, 0)); return NULL; } - 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 = calloc(1, sizeof (char) * (size + 1)); - if (alloc) - memcpy(alloc, str, size); - else - goto oom; - return alloc; - } - /* Even empty quotes counts as a value (An empty string) */ - alloc = (char *)calloc(1, sizeof (char)); - if (!alloc) - goto oom; - for (i = 2; i < VECTOR_SIZE(strvec); i++) { - str = VECTOR_SLOT(strvec, i); - if (!str) { - free(alloc); - condlog(0, "parse error for option '%s'", - (char *)VECTOR_SLOT(strvec, 0)); - return NULL; + if (is_quote(str)) { + if (VECTOR_SIZE(strvec) > 2) { + str = VECTOR_SLOT(strvec, 2); + if (!str) { + condlog(0, "parse error for option '%s'", + (char *)VECTOR_SLOT(strvec, 0)); + return NULL; + } } - if (is_quote(str)) - break; - tmp = alloc; - /* The first +1 is for the NULL byte. The rest are for the - * spaces between words */ - len += strlen(str) + 1; - alloc = realloc(alloc, sizeof (char) * len); - if (!alloc) { - free(tmp); - goto oom; + /* Even empty quotes counts as a value (An empty string) */ + if (is_quote(str)) { + alloc = (char *)calloc(1, sizeof (char)); + if (!alloc) + goto oom; + return alloc; } - if (*alloc != '\0') - strncat(alloc, " ", len - strlen(alloc)); - strncat(alloc, str, len - strlen(alloc) - 1); } - return alloc; + alloc = strdup(str); + if (alloc) + return alloc; oom: condlog(0, "can't allocate memory for option '%s'", (char *)VECTOR_SLOT(strvec, 0)); @@ -442,7 +416,6 @@ int validate_config_strvec(vector strvec, const char *file) { char *str = NULL; - int i; if (strvec && VECTOR_SIZE(strvec) > 0) str = VECTOR_SLOT(strvec, 0); @@ -485,21 +458,41 @@ validate_config_strvec(vector strvec, const char *file) condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, 2), line_nr, file); return 0; } - for (i = 2; i < VECTOR_SIZE(strvec); i++) { - str = VECTOR_SLOT(strvec, i); - if (str == NULL) { - condlog(0, "can't parse value on line %d of %s", - line_nr, file); - return -1; - } - 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; - } + if (VECTOR_SIZE(strvec) == 2) { + condlog(0, "missing closing quotes on line %d of %s", + line_nr, file); + return 0; + } + str = VECTOR_SLOT(strvec, 2); + if (str == NULL) { + condlog(0, "can't parse value on line %d of %s", + line_nr, file); + return -1; + } + if (is_quote(str)) { + if (VECTOR_SIZE(strvec) > 3) + condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, 3), line_nr, file); + return 0; + } + if (VECTOR_SIZE(strvec) == 3) { + condlog(0, "missing closing quotes on line %d of %s", + line_nr, file); + return 0; + } + str = VECTOR_SLOT(strvec, 3); + if (str == NULL) { + condlog(0, "can't parse value on line %d of %s", + line_nr, file); + return -1; + } + if (!is_quote(str)) { + /* There should only ever be one token between quotes */ + condlog(0, "parsing error starting with '%s' on line %d of %s", + str, line_nr, file); + return -1; } - condlog(0, "missing closing quotes on line %d of %s", - line_nr, file); + if (VECTOR_SIZE(strvec) > 4) + condlog(0, "ignoring extra data starting with '%s' on line %d of %s", (char *)VECTOR_SLOT(strvec, 4), line_nr, file); return 0; } From patchwork Wed Dec 14 21:38:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13073591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55665C4332F for ; Wed, 14 Dec 2022 21:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671053937; 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=1pb4XUOvGcJEQZJtD8r27eonamHwE5o5zAVYvs1g0Es=; b=ZU7GKIW6UtRUvu9kGCL154o9rB58rCXUa72F5Hjkzsc+tvzLw0SstPASqQnEOEc6i8KVLm Z0OXu+tHc2hwfWBmEIwf7KNFEr/5RAdhs01qYOS0Kp28lqK9CR7zi42s9RFkJ1z1yHpUKl +mwCG0KZze6R0Q2GD7mBdlrx5k7EAZA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-574-WTLJW4m6Nfii-fbPAxDaEg-1; Wed, 14 Dec 2022 16:38:56 -0500 X-MC-Unique: WTLJW4m6Nfii-fbPAxDaEg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27DEC280BCA4; Wed, 14 Dec 2022 21:38:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C208A2026D33; Wed, 14 Dec 2022 21:38:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 907F11946A4B; Wed, 14 Dec 2022 21:38:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 694BB1946A42 for ; Wed, 14 Dec 2022 21:38:25 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A32A1400D79C; Wed, 14 Dec 2022 21:38:25 +0000 (UTC) Received: from octiron.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E29C40BC781; Wed, 14 Dec 2022 21:38:25 +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 2BELcORk014967; Wed, 14 Dec 2022 15:38:24 -0600 Received: (from bmarzins@localhost) by octiron.msp.redhat.com (8.14.9/8.14.9/Submit) id 2BELcNHp014966; Wed, 14 Dec 2022 15:38:23 -0600 From: Benjamin Marzinski To: Christophe Varoqui Date: Wed, 14 Dec 2022 15:38:19 -0600 Message-Id: <1671053900-14923-3-git-send-email-bmarzins@redhat.com> In-Reply-To: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> References: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH V2 2/3] libmultipath: don't leak memory on invalid strings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: device-mapper development , Martin Wilck MIME-Version: 1.0 Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com If set_path() or set_str_noslash() are called with a bad value, they ignore it and continue to use the old value. But they weren't freeing the bad value, causing a memory leak. Signed-off-by: Benjamin Marzinski --- libmultipath/dict.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 97f43387..f4233882 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -130,6 +130,7 @@ set_path(vector strvec, void *ptr, const char *file, int line_nr) if ((*str_ptr)[0] != '/'){ condlog(1, "%s line %d, %s is not an absolute path. Ignoring", file, line_nr, *str_ptr); + free(*str_ptr); *str_ptr = old_str; } else free(old_str); @@ -150,6 +151,7 @@ set_str_noslash(vector strvec, void *ptr, const char *file, int line_nr) if (strchr(*str_ptr, '/')) { condlog(1, "%s line %d, %s cannot contain a slash. Ignoring", file, line_nr, *str_ptr); + free(*str_ptr); *str_ptr = old_str; } else free(old_str); From patchwork Wed Dec 14 21:38:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 13073594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 12759C4332F for ; Wed, 14 Dec 2022 21:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671053955; 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=ENjY3XtwQ9vApLz8RiCTgMSU7HSfnRMubOuXQqK2PwU=; b=a/OuYdL0OU5H3Cse+NOVtlImAka737udOc+KN2eqzLtqjrsR3nmWsksQCawmj4ZENPTV2n YEIBOgTKjuxsnmTe7hoCsiMYAGfvd7UqBxwQmA+ChuE/y2HmRf+aMLrhfDiO9H/oT9zG0c VS59Q1mK013/2scHP3Aq/Y+/UkiZ6HM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-457-9mo-XsZgPFy_R7p6qwzmyg-1; Wed, 14 Dec 2022 16:38:56 -0500 X-MC-Unique: 9mo-XsZgPFy_R7p6qwzmyg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 28ABC280BCA6; Wed, 14 Dec 2022 21:38:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70A12400F5F; Wed, 14 Dec 2022 21:38:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0C0A91946A6B; Wed, 14 Dec 2022 21:38:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 673E31946A41 for ; Wed, 14 Dec 2022 21:38:27 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F2928400D79D; Wed, 14 Dec 2022 21:38:26 +0000 (UTC) Received: from octiron.msp.redhat.com (octiron.msp.redhat.com [10.15.80.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D404740C945A; Wed, 14 Dec 2022 21:38:26 +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 2BELcP89014971; Wed, 14 Dec 2022 15:38:25 -0600 Received: (from bmarzins@localhost) by octiron.msp.redhat.com (8.14.9/8.14.9/Submit) id 2BELcP0n014970; Wed, 14 Dec 2022 15:38:25 -0600 From: Benjamin Marzinski To: Christophe Varoqui Date: Wed, 14 Dec 2022 15:38:20 -0600 Message-Id: <1671053900-14923-4-git-send-email-bmarzins@redhat.com> In-Reply-To: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> References: <1671053900-14923-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Subject: [dm-devel] [PATCH V2 3/3] libmutipath: validate the argument count of config strings X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: device-mapper development , Martin Wilck MIME-Version: 1.0 Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com The features, path_selector, and hardware_handler config options pass their strings directly into the kernel. If users omit the argument counts from these strings, or use the wrong value, the kernel's table parsing gets completely messed up, and the error messages it prints don't reflect what actully went wrong. To avoid messing up the kernel table parsing, verify that these strings correctly set the argument count to the number of arguments they have. Signed-off-by: Benjamin Marzinski --- libmultipath/dict.c | 110 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 9 deletions(-) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index f4233882..2e9b45f9 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -116,6 +116,58 @@ set_str(vector strvec, void *ptr, const char *file, int line_nr) return 0; } +static int +set_arg_str(vector strvec, void *ptr, int count_idx, const char *file, + int line_nr) +{ + char **str_ptr = (char **)ptr; + char *old_str = *str_ptr; + const char * const spaces = " \f\r\t\v"; + char *p, *end; + int idx = -1; + long int count = -1; + + *str_ptr = set_value(strvec); + if (!*str_ptr) { + free(old_str); + return 1; + } + p = *str_ptr; + while (*p != '\0') { + p += strspn(p, spaces); + if (*p == '\0') + break; + idx += 1; + if (idx == count_idx) { + errno = 0; + count = strtol(p, &end, 10); + if (errno == ERANGE || end == p || + !(isspace(*end) || *end == '\0')) { + count = -1; + break; + } + } + p += strcspn(p, spaces); + } + if (count < 0) { + condlog(1, "%s line %d, missing argument count for %s", + file, line_nr, (char*)VECTOR_SLOT(strvec, 0)); + goto fail; + } + if (count != idx - count_idx) { + condlog(1, "%s line %d, invalid argument count for %s:, got '%ld' expected '%d'", + file, line_nr, (char*)VECTOR_SLOT(strvec, 0), count, + idx - count_idx); + goto fail; + } + free(old_str); + return 0; +fail: + free(*str_ptr); + *str_ptr = old_str; + return 0; +} + static int set_path(vector strvec, void *ptr, const char *file, int line_nr) { @@ -288,6 +340,14 @@ def_ ## option ## _handler (struct config *conf, vector strvec, \ return set_int(strvec, &conf->option, minval, maxval, file, line_nr); \ } +#define declare_def_arg_str_handler(option, count_idx) \ +static int \ +def_ ## option ## _handler (struct config *conf, vector strvec, \ + const char *file, int line_nr) \ +{ \ + return set_arg_str(strvec, &conf->option, count_idx, file, line_nr); \ +} + #define declare_def_snprint(option, function) \ static int \ snprint_def_ ## option (struct config *conf, struct strbuf *buff, \ @@ -340,6 +400,17 @@ hw_ ## option ## _handler (struct config *conf, vector strvec, \ return set_int(strvec, &hwe->option, minval, maxval, file, line_nr); \ } +#define declare_hw_arg_str_handler(option, count_idx) \ +static int \ +hw_ ## option ## _handler (struct config *conf, vector strvec, \ + const char *file, int line_nr) \ +{ \ + struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable); \ + if (!hwe) \ + return 1; \ + return set_arg_str(strvec, &hwe->option, count_idx, file, line_nr); \ +} + #define declare_hw_snprint(option, function) \ static int \ @@ -371,6 +442,16 @@ ovr_ ## option ## _handler (struct config *conf, vector strvec, \ file, line_nr); \ } +#define declare_ovr_arg_str_handler(option, count_idx) \ +static int \ +ovr_ ## option ## _handler (struct config *conf, vector strvec, \ + const char *file, int line_nr) \ +{ \ + if (!conf->overrides) \ + return 1; \ + return set_arg_str(strvec, &conf->overrides->option, count_idx, file, line_nr); \ +} + #define declare_ovr_snprint(option, function) \ static int \ snprint_ovr_ ## option (struct config *conf, struct strbuf *buff, \ @@ -401,6 +482,17 @@ mp_ ## option ## _handler (struct config *conf, vector strvec, \ return set_int(strvec, &mpe->option, minval, maxval, file, line_nr); \ } +#define declare_mp_arg_str_handler(option, count_idx) \ +static int \ +mp_ ## option ## _handler (struct config *conf, vector strvec, \ + const char *file, int line_nr) \ +{ \ + struct mpentry * mpe = VECTOR_LAST_SLOT(conf->mptable); \ + if (!mpe) \ + return 1; \ + return set_arg_str(strvec, &mpe->option, count_idx, file, line_nr); \ +} + #define declare_mp_snprint(option, function) \ static int \ snprint_mp_ ## option (struct config *conf, struct strbuf *buff, \ @@ -584,13 +676,13 @@ snprint_def_marginal_pathgroups(struct config *conf, struct strbuf *buff, } -declare_def_handler(selector, set_str) +declare_def_arg_str_handler(selector, 1) declare_def_snprint_defstr(selector, print_str, DEFAULT_SELECTOR) -declare_hw_handler(selector, set_str) +declare_hw_arg_str_handler(selector, 1) declare_hw_snprint(selector, print_str) -declare_ovr_handler(selector, set_str) +declare_ovr_arg_str_handler(selector, 1) declare_ovr_snprint(selector, print_str) -declare_mp_handler(selector, set_str) +declare_mp_arg_str_handler(selector, 1) declare_mp_snprint(selector, print_str) static int snprint_uid_attrs(struct config *conf, struct strbuf *buff, @@ -663,13 +755,13 @@ declare_hw_snprint(prio_args, print_str) declare_mp_handler(prio_args, set_str) declare_mp_snprint(prio_args, print_str) -declare_def_handler(features, set_str) +declare_def_arg_str_handler(features, 0) declare_def_snprint_defstr(features, print_str, DEFAULT_FEATURES) -declare_ovr_handler(features, set_str) +declare_ovr_arg_str_handler(features, 0) declare_ovr_snprint(features, print_str) -declare_hw_handler(features, set_str) +declare_hw_arg_str_handler(features, 0) declare_hw_snprint(features, print_str) -declare_mp_handler(features, set_str) +declare_mp_arg_str_handler(features, 0) declare_mp_snprint(features, print_str) declare_def_handler(checker_name, set_str) @@ -1821,7 +1913,7 @@ declare_hw_snprint(revision, print_str) declare_hw_handler(bl_product, set_str) declare_hw_snprint(bl_product, print_str) -declare_hw_handler(hwhandler, set_str) +declare_hw_arg_str_handler(hwhandler, 0) declare_hw_snprint(hwhandler, print_str) /*