From patchwork Fri Dec 1 11:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3496 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:d588:b0:fb:b703:d903 with SMTP id ev8csp266596dyc; Fri, 1 Dec 2023 03:23:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp32z94hc0mxXEVH4h6b1lV6Azz+31g+DgnZ1dYAk8uKGnJfgn5UXnwOAWXIbo120XC36n X-Received: by 2002:a17:90b:713:b0:283:5405:9e90 with SMTP id s19-20020a17090b071300b0028354059e90mr24628648pjz.3.1701429830295; Fri, 01 Dec 2023 03:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701429830; cv=none; d=google.com; s=arc-20160816; b=lfMkKA7JFUUlEIABlKF4h4YE6LQQBuMFwM2gjHVmMi/VahxtSgAzuLLf7dd9q8keaV EOECGjuB4KdSUr7xnUEvCD+4LVthW5nAVyTpwsNG8mHesAvFQeXU8Mqhv9BMgXVFqb77 ZTGEwqsJXyfSoGoGtIMkPzW/SXoIGykBGDBRjg2xCKESORER7RnkaJEPQcq7IvfxKayX l1yIPOqfz1+yrhEP+66AU8XyeohofJM54ObV7yBFyECc/zlh6i7P4gB/Jq2kazbc5Cva gWd/TmF+GiKHyn9s8uB0U1eFvEH7oXjIKQekABUtTmtSyjEEIuuBaT9kqvqFx+YbCwUZ G6Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=URVPjahspZxgrjFhZjb1TCfduiG8HXEAmqonRHFv0iE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=vESrrzCbUKeD3qITfPXULazhJViwTim4nCfJ88IGxEdOoUNnzdLQl/fuLLvc8VpofO j/U3gsBShCj0zYjRDEBV8SNlGTdNZXXcLGTEFhDR3cbSf8qX8cblEgux538b3LMcIIzk tOl09gnVoKtb2mY00EZ2MAt//dnqt6neu36K6O2r8jIB70I0xzl2/HC8FdYq0TcGs91l pBKvMPTMsdUWXcopfEdmDjKi0VXoOX0A7zVd3dfsVSmRr5Q2TUUz3nkIuRbemeUb3CXw J4cQm24qFgVPAdoDZ1JcIzlgnXoErRG0+3YJUti38ZQzXTjor+MrAy6ofLBBBxl2wTyU WY8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=EUrMf4AD; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iPgQGHij; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=qW0qDAyu; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id x4-20020a17090a970400b00285ca5d2636si3265467pjo.123.2023.12.01.03.23.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2023 03:23:50 -0800 (PST) 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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=EUrMf4AD; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=iPgQGHij; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=qW0qDAyu; 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 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 1r91bp-0005sk-Vz; Fri, 01 Dec 2023 11:23:02 +0000 Received: from [172.30.20.202] (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 1r91bo-0005sU-77 for openvpn-devel@lists.sourceforge.net; Fri, 01 Dec 2023 11:23:00 +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:Cc:To:From:Sender:Reply-To: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=//BpfSGjmDav49pNyKLVzA9wOSrtXtjiKixwFmAnbYQ=; b=EUrMf4ADsr/BD9p81Qg2Jdsx+j mQQ3zWJjk8bQ1i6jH++ZMqThzYoPjPDmLrAJW6wBq9tHKKKiJQ0goCT+ucZNZoO21xpwVdANji2CD ktP8gX3GGYStczxG+OtYW+0kilU1UCtA9mQOGWo13WTjp+4qIcMNgkBMyp3ojklxa85A=; 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:Cc:To:From:Sender:Reply-To: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=//BpfSGjmDav49pNyKLVzA9wOSrtXtjiKixwFmAnbYQ=; b=iPgQGHij7WjeH7a4lHvXCXLcIo VgrUmFeO7MKRHDec8G22H1JdVTex51qDMA7jMNdxkP37eW7rZqI6FuJ+Km90yDDgA2boeB5OJDuyw IDeRShkKKz9J9iEyWN3pq22t4K8jjIeTxOjxwWF2OFPSG7pIPLTi9Ccq46TYlh1jsTGw=; Received: from mout-p-103.mailbox.org ([80.241.56.161]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1r91bn-0008Jr-DQ for openvpn-devel@lists.sourceforge.net; Fri, 01 Dec 2023 11:23:00 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4ShVzB05wzz9sqF; Fri, 1 Dec 2023 12:22:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1701429766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=//BpfSGjmDav49pNyKLVzA9wOSrtXtjiKixwFmAnbYQ=; b=qW0qDAyuraBv74sX+BnmO26y2QNToB5nAi2m+b2wDobrCJAzeFXt+T/zt4Au9g9qXS2+r8 0FO0bez2UNKCfhJb61Wo1ReSGHWq+bp7W7EO9USHlvN5Drm9XLQk5mdr3RWBmjAg9WeTCn PGNXQqVfwyGuVgyFONvNj5LgXPtVQjX9GU6frHsUmfCkDyHhoSwbacvbgyEkqq2kmb0RV9 +WQ4BDD3KxlEDncRgmG7ovkc3O8NQU33oM5Z3eb5WbCzba9WYWQSyqZp7vTLd7y/m3EsBd a+za9Gmybb4VMGmSMR2etn2bTPoSxG/K0jocxRralOnKD5TjkKMxfKTXJMutAQ== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Fri, 1 Dec 2023 12:22:43 +0100 Message-Id: <20231201112243.15541-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4ShVzB05wzz9sqF X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", 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: Arne Schwabe Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: openvpn.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.161 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1r91bn-0008Jr-DQ Subject: [Openvpn-devel] [PATCH v1] Replace character_class_debug with proper unit test 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?1784078485967446202?= X-GMAIL-MSGID: =?utf-8?q?1784078485967446202?= From: Arne Schwabe Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld --- 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/+/464 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld Note: this requires "Remove dead remains of extract_x509_field_test" (https://gerrit.openvpn.net/c/openvpn/+/462) to be applied first. diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 24f1ef2..0b94a52 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -1150,26 +1150,6 @@ } } -#ifdef CHARACTER_CLASS_DEBUG - -#define CC_INCLUDE (CC_PRINT) -#define CC_EXCLUDE (0) -#define CC_REPLACE ('.') - -void -character_class_debug(void) -{ - char buf[256]; - - while (fgets(buf, sizeof(buf), stdin) != NULL) - { - string_mod(buf, CC_INCLUDE, CC_EXCLUDE, CC_REPLACE); - printf("%s", buf); - } -} - -#endif - #ifdef VERIFY_ALIGNMENT void valign4(const struct buffer *buf, const char *file, const int line) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 4cc7950..0456b27 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -896,8 +896,6 @@ */ const char *np(const char *str); -/*#define CHARACTER_CLASS_DEBUG*/ - /* character classes */ #define CC_ANY (1<<0) @@ -961,11 +959,6 @@ } -#ifdef CHARACTER_CLASS_DEBUG -void character_class_debug(void); - -#endif - /* * Verify that a pointer is correctly aligned */ diff --git a/src/openvpn/init.c b/src/openvpn/init.c index fdab26b..9972ed7 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -875,11 +875,6 @@ return false; #endif -#ifdef CHARACTER_CLASS_DEBUG - character_class_debug(); - return false; -#endif - #ifdef TIME_TEST time_test(); return false; diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index 8232f92..f994812 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -319,6 +319,30 @@ gc_free(&gc); } +static void +test_character_class(void **state) +{ + char buf[256]; + strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!"); + string_mod(buf, CC_PRINT, 0, '@'); + assert_string_equal(buf, "There is @ a nice 1234 year old tr@ ee!"); + + strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!"); + string_mod(buf, CC_PRINT, CC_DIGIT, '@'); + assert_string_equal(buf, "There is @ a nice @@@@ year old tr@ ee!"); + + strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!"); + string_mod(buf, CC_ALPHA, CC_DIGIT, '.'); + assert_string_equal(buf, "There.is...a.nice......year.old.tr..ee."); + + strcpy(buf, "There is \x01 a 'nice' \"1234\"\n year old \ntr\x7f ee!"); + string_mod(buf, CC_ALPHA|CC_DIGIT|CC_NEWLINE|CC_SINGLE_QUOTE, CC_DOUBLE_QUOTE|CC_BLANK, '.'); + assert_string_equal(buf, "There.is...a.'nice'..1234.\n.year.old.\ntr..ee."); + + strcpy(buf, "There is a \\'nice\\' \"1234\" [*] year old \ntree!"); + string_mod(buf, CC_PRINT, CC_BACKSLASH|CC_ASTERISK, '.'); + assert_string_equal(buf, "There is a .'nice.' \"1234\" [.] year old .tree!"); +} int main(void) @@ -351,6 +375,7 @@ cmocka_unit_test(test_buffer_free_gc_one), cmocka_unit_test(test_buffer_free_gc_two), cmocka_unit_test(test_buffer_gc_realloc), + cmocka_unit_test(test_character_class), }; return cmocka_run_group_tests_name("buffer", tests, NULL, NULL);