From patchwork Wed Oct 8 10:02:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4478 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id fr2csp816088mab; Wed, 8 Oct 2025 03:02:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXeq6TIyLEHPmw3udy8lWsuHMZ0hN1X0CNJEKqM+IzUvINoRA4YB44nQSfIadokLGjPiTuJz4OS3go=@openvpn.net X-Google-Smtp-Source: AGHT+IEObck/Q4/gkXOJP9XwYew62I5oFOZ41u4rQyZNu00fgY4kl9UDBHc+seG5kOKyWPN+y7bX X-Received: by 2002:a05:6830:6017:b0:745:4823:df18 with SMTP id 46e09a7af769-7c0df7d9f88mr1688060a34.28.1759917762128; Wed, 08 Oct 2025 03:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1759917762; cv=none; d=google.com; s=arc-20240605; b=b3dy+ygRcv5cdthpx+UkATSVwGvavaOZ/jNyjswD0+xupe5xuh8ZWe/363FW+R2qFW thLiucVIxNQpeEKj7DMH6IQfD3wOkoSvV6gHYLzpsZsv6SnVN8OiC93F/MTicHYNPS2V 4jrLix/Iihr5476BLUm5eq64TNNO81o00JaiiRF4SiWELeIeDqIvAWg7wSVeurlBLkE1 kEuRGEexJd7nFb+wgl77ar2a32Q86l/ikr5AIw/iRV5Bm7CMNxMFAr5ahuBo6qlZV5w8 sBJsHYQWKH1/hBRVPYXFyEba0Z6RekxAvVbNiIMB4gmfcuThDLl34W08ouKNzt+44TYb 0/bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=wLIkQOrd/0nll9+nwmTjb7hFIzfQuRD7LG1jOorpGx0=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=F+OBNXDGpbbtYVi8FctZD86IrZuMEmSgZnX4QlJ8uVFr4R8jK1h2GL1VjuEEbTya4p arkM3ja2uWU6udMcGvXG0eOqf8SVeNBB3EImYChffypZkB3Vwssmst4BtodG0dnRmeIm Hdv6cvsLGl+ZFKJ79l0r2Y+WxkneHEc6VVNwlEHhQ7eiPg7C/JG/xytygaz3ciH3nt+i aLxwWfbm00mhSFPMQaC/2uJdnae93IpNIxcm/mYzIs9aZBXeIz83QEE/QA0kz3MTwV2W 0j35ZaeG6IhHsQlM+Zw08hxhXoDLgcIEc12MobMuXGWtOo0sHlHp3e5qWI6jeBEqv968 UK0g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=A8TUX9JM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=flkIpSWO; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=lkSOLbTI; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-7c06be35048si1222748a34.289.2025.10.08.03.02.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Oct 2025 03:02:42 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=A8TUX9JM; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=flkIpSWO; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=lkSOLbTI; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wLIkQOrd/0nll9+nwmTjb7hFIzfQuRD7LG1jOorpGx0=; b=A8TUX9JMXo6Pahv3ovZF+p3at6 t++9VK9By60xnKV02H9SQ5Z/bPqVJz2V+SkODjK6OsgAnyj8jkuQZYyf5ghkewgVviO/XyyuywK9b 6nT/03ABX4ecItHCIg/xwC2lFLQR7eqhiUGI52qYXN7dNFrfOKLrPYDgx0H63CCRFK+8=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v6R0H-0002Dj-O7; Wed, 08 Oct 2025 10:02:38 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v6R0E-0002DT-RZ for openvpn-devel@lists.sourceforge.net; Wed, 08 Oct 2025 10:02:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CkHUNlT2gsTHXkl7w3Q+YtsFcO5FlmOZk453Khcr6ZM=; b=flkIpSWOqehLiFDVF6fdj44P2/ xveQ134zJSYjo4cmw/IxKw99agqHWpJCEJuuh0k8hH3EZNZU5XzxHeZMb+nG3lZORF9kDHUkLwBKZ 3iS/6Xxn2N63YUMHalPf4lK9zGRoWQdwD8Gs53rDBsGOqGxHQ/lv4+W3al++Y7noX3NQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CkHUNlT2gsTHXkl7w3Q+YtsFcO5FlmOZk453Khcr6ZM=; b=lkSOLbTI78TdWaizMGo+D99WG2 +SFqCWfsWbhgfcBXXKgvN7rIQnVFEHurLxS922uL2lY1bQ246pM4UHEUcx2gg0e044/NjDDOYdBm2 yDESjhl0QMiaGyZ8JyIfKYvs7uJGOgedrEGoPzMTS9U8oPFRHrT9QW3zF6WX10irZKqY=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1v6R0E-0003Es-HD for openvpn-devel@lists.sourceforge.net; Wed, 08 Oct 2025 10:02:35 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 598A2MkR004673 for ; Wed, 8 Oct 2025 12:02:22 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 598A2MCP004672 for openvpn-devel@lists.sourceforge.net; Wed, 8 Oct 2025 12:02:22 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 8 Oct 2025 12:02:16 +0200 Message-ID: <20251008100222.4610-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld The test discovered the issue fixed by commit "buffer: Fix buf_parse eating input". Change-Id: Icb91d9c560b6f78f16571ac3052cc566d94afe99 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1v6R0E-0003Es-HD Subject: [Openvpn-devel] [PATCH v2] test_options_parse: Add test for read_config_string X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1845407527361991319?= X-GMAIL-MSGID: =?utf-8?q?1845407527361991319?= From: Frank Lichtenheld The test discovered the issue fixed by commit "buffer: Fix buf_parse eating input". Change-Id: Icb91d9c560b6f78f16571ac3052cc566d94afe99 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1247 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1247 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/tests/unit_tests/openvpn/test_options_parse.c b/tests/unit_tests/openvpn/test_options_parse.c index 9472c78..e552dd7 100644 --- a/tests/unit_tests/openvpn/test_options_parse.c +++ b/tests/unit_tests/openvpn/test_options_parse.c @@ -43,6 +43,9 @@ const unsigned int permission_mask, unsigned int *option_types_found, struct env_set *es) { + function_called(); + check_expected(p); + check_expected(is_inline); } void @@ -185,11 +188,117 @@ gc_free(&gc); } +static void +read_single_config(struct options *options, const char *config) +{ + unsigned int option_types_found = 0; + struct env_set es; + CLEAR(es); + read_config_string("test_options_parse", options, config, M_INFO, OPT_P_DEFAULT, + &option_types_found, &es); +} + +union tokens_parameter +{ + uintmax_t as_int; + void *as_pointer; +}; + +static int +check_tokens(const uintmax_t value, const uintmax_t expected) +{ + union tokens_parameter temp; + temp.as_int = value; + const char **p = (const char **)temp.as_pointer; + temp.as_int = expected; + const char **expected_p = (const char **)temp.as_pointer; + for (int i = 0; i < MAX_PARMS; i++) + { + if (!p[i] && !expected_p[i]) + { + return true; + } + if ((p[i] && !expected_p[i]) + || (!p[i] && expected_p[i])) + { + fprintf(stderr, "diff at i=%d\n", i); + return false; + } + if (strcmp(p[i], expected_p[i])) + { + fprintf(stderr, "diff at i=%d, p=<%s> ep=<%s>\n", i, p[i], expected_p[i]); + return false; + } + } + fprintf(stderr, "fallthrough"); + return false; +} + +static void +test_read_config(void **state) +{ + struct options o; + CLEAR(o); /* NB: avoiding init_options to limit dependencies */ + gc_init(&o.gc); + gc_init(&o.dns_options.gc); + o.gc_owned = true; + + char *p_expect_someopt[MAX_PARMS]; + char *p_expect_otheropt[MAX_PARMS]; + char *p_expect_inlineopt[MAX_PARMS]; + CLEAR(p_expect_someopt); + CLEAR(p_expect_otheropt); + CLEAR(p_expect_inlineopt); + p_expect_someopt[0] = "someopt"; + p_expect_someopt[1] = "parm1"; + p_expect_someopt[2] = "parm2"; + p_expect_otheropt[0] = "otheropt"; + p_expect_otheropt[1] = "1"; + p_expect_otheropt[2] = "2"; + p_expect_inlineopt[0] = "inlineopt"; + p_expect_inlineopt[1] = "some text\nother text\n"; + + /* basic test */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_someopt); + expect_value(__wrap_add_option, is_inline, 0); + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_otheropt); + expect_value(__wrap_add_option, is_inline, 0); + read_single_config(&o, "someopt parm1 parm2\n otheropt 1 2"); + + /* -- gets stripped */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_someopt); + expect_value(__wrap_add_option, is_inline, 0); + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_otheropt); + expect_value(__wrap_add_option, is_inline, 0); + read_single_config(&o, "someopt parm1 parm2\n\t--otheropt 1 2"); + + /* inline options */ + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_inlineopt); + expect_value(__wrap_add_option, is_inline, 1); + read_single_config(&o, "\nsome text\nother text\n"); + + p_expect_inlineopt[0] = "inlineopt"; + p_expect_inlineopt[1] = A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 "\n"; + expect_function_call(__wrap_add_option); + expect_check(__wrap_add_option, p, check_tokens, p_expect_inlineopt); + expect_value(__wrap_add_option, is_inline, 1); + read_single_config(&o, "\n" A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 A_TIMES_256 "\n"); + + gc_free(&o.gc); + gc_free(&o.dns_options.gc); +} + int main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_parse_line), + cmocka_unit_test(test_read_config), }; return cmocka_run_group_tests_name("options_parse", tests, NULL, NULL);