From patchwork Thu Nov 30 16:24:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "plaisthos (Code Review)" X-Patchwork-Id: 3490 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:150c:b0:fb:b703:d903 with SMTP id ml12csp306088dyb; Thu, 30 Nov 2023 08:25:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbbGDTPjtNzyB3y2sq/9vEr3bvyOwQ0fiEWtn4jfC3Vixv5QBy+FIT6dfqGwkC7S5FLxTQ X-Received: by 2002:a05:6a00:2191:b0:6cd:dfff:19b6 with SMTP id h17-20020a056a00219100b006cddfff19b6mr4488836pfi.2.1701361556770; Thu, 30 Nov 2023 08:25:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701361556; cv=none; d=google.com; s=arc-20160816; b=G89pW1Ns8fYClsTmP8qHtVOmHt0RH6pQ7XMs9WUTqdSEKL7Z798BpckrMSgmqeZ9rz fzcA1golNG01wDPsyGivcbaRSLfpJ1/989b3fYdN1OuA3C+7KCPpGsZb8+nLUzGkFfEd b8nxC1tJzSFgisgbqYct6Bmsdcs4OzZvDuzYm8qLbkwudogClY43cSJvrK/vLVIM22zg tIh2gACFKwjHC40fBXXabQZQBDDTV5A17+XpTU/dElnKl7kxSz+qU/bWy4RFPKrKdQdV JGrDvLIC6Oq+pUYhtN98jxpqnphQIbdLcaEJcm0ESoWi2pk7pmZYPbTimU55aR9u4zQq GKrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=GgoCtwa6q0XgDxdnkyb3Fx8GfdA/T7ZusV8dgRv+VTQ=; fh=lm0MLPW7DntlrDqRECIiC9JlE1uPxhepE0URYHIf+eE=; b=jL8hoIATwB/LpNrauhuVsyrGqocZ8dKajlLk1LZx8KAS2MprV4RAu4mai9kWJImuI0 S7oG0Ppx4KU4CMvSM/PIT4G69j71W7/0Xts0i6+VwF2Jwl3+4RpPgtOFfWWT6hoDGk7s IKn02w6RD+X2HEwAwmjEtE/+uRhSzqpnMXyrkbqWo7LJa7+PJlgHqcD78hL9FsrqkU63 jIy8r9SxqPL/RWtwYlFOP09YM8H+RNh2RiQS3aJHJMRXCGMddA/i1iVtPo6T5CfqBxJ5 hoOn/oe/1xG5PAkf/k3aKaZbPa1U87mlkcq/7J8cVqo8suVeSXFsWRtm/8IVBByJyiWu EKOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=R+bnQdnw; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LmB1kJPF; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=IgR8jzSp; 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=openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id fh41-20020a056a00392900b00690c23d353asi1536631pfb.217.2023.11.30.08.25.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2023 08:25:56 -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=R+bnQdnw; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LmB1kJPF; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=IgR8jzSp; 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=openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1r8jqu-0000bK-Ox; Thu, 30 Nov 2023 16:25:25 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r8jqe-0000b9-24 for openvpn-devel@lists.sourceforge.net; Thu, 30 Nov 2023 16:25:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2WEuAaQpVt0SwTIIVodfxEAUgdPd2UtPif9wzMBg/oA=; b=R+bnQdnwE6gwT3Utg1xe/6D9zZ bdH4c1MSVlbrvjWkJ/JjdWp+7/Pam8XOCgfLrMYDSQkpESri7/eGzda1uXGQ966vWfVZKQBkTzZs9 VrrYgKYmx/fLBvWI9UJYYsR6soc0CYiyXKPH4PeODJvzVkF27DXRdehV8/ZgcgIDOi58=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=2WEuAaQpVt0SwTIIVodfxEAUgdPd2UtPif9wzMBg/oA=; b=L mB1kJPF3xItnZFlzuMFFkN2GBip3/yrHdZLPSVIUHIE+QlH3nwElt9D8/AbRca6AVfhanQ85EcbFb IlqkzV0bbXMcD+1hy0azY6aI4w6UCfrk+Wa0zGCRzxZYm23SF6+2bbxVl4XpUP7Du73DmoSVgTKYm vWYu32VvlKg8sunc=; Received: from mail-lf1-f43.google.com ([209.85.167.43]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1r8jqX-0006u3-T9 for openvpn-devel@lists.sourceforge.net; Thu, 30 Nov 2023 16:25:07 +0000 Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-50bd4fcbde1so411666e87.1 for ; Thu, 30 Nov 2023 08:24:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1701361481; x=1701966281; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=2WEuAaQpVt0SwTIIVodfxEAUgdPd2UtPif9wzMBg/oA=; b=IgR8jzSpdBSlKA+5pO3uBPjnyvKmDw0pytJTJcAFgKYYSu1cr/6qh/dXdgDcgsG4D+ 17ks8uz13Dg6WVArShmsWjUcztL0sujRJFM5BjdAnQ5SjVaP9TLirsy+lcIW4ITFbgCX R4M4ecWu8ZMAped/5w/HlY7cYVwjEMcIfmJQRR7QTlu4ch9wtXM4dRf5TJGXanj3ENS6 ZxwvY4oOrO6Z9yq9VWxMam7mbtLR5VEOYa1YoEOsYEFHLeosB01UXvoSMO6kVqjn18f8 dQ69UTRNi9mJY7G+kmNJ9rIV9a0C80PGIVQOAqi0cfOxWrchZlDzhim4x1g7/3osiNWS lF8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701361481; x=1701966281; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2WEuAaQpVt0SwTIIVodfxEAUgdPd2UtPif9wzMBg/oA=; b=rCsI/v3R6es8sJwTxarEFJx+a/MdM6oWbd65ILVaEnlRJzJ8IuxJgW56BAA2UU0pyD LAeZGW/q5X5lQSLN1SAmlv42W5WGj77kxho9mdjv2b6g4ELcX6iK38XCV2fJIs+VddKF Q2/b/Yv7EHILgnPnps7wUJBKovEY3eB6g0rHfr0d6HbCUKr6hT8Io96PQXa7voBA+5zj uFeyOW8rAde3Awp9S/7Tk6Wt7woe39De/Aik0SdKaU0SYh+h824wHdEL3ES+labeI2KO iVfb4KfvQ/LlszuH/2q8csG2CU2IDYE7qmwLTA/OAQuikYW++ar7tWIvWmXWqquTSDZj R5zQ== X-Gm-Message-State: AOJu0YwZ/e2OCi6qAtL2NS2scZYSPHTemAEH2BWqEVzYDikq+rI3WQ2S C7bBsh8dCM7lfNow+d6yDNtnb5zfJD7XVwh1XDY= X-Received: by 2002:a05:6512:210c:b0:50b:bcea:c979 with SMTP id q12-20020a056512210c00b0050bbceac979mr4287lfr.53.1701361480740; Thu, 30 Nov 2023 08:24:40 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id u11-20020adfa18b000000b00332cc7c3aaasm1945898wru.21.2023.11.30.08.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 08:24:40 -0800 (PST) From: "plaisthos (Code Review)" X-Google-Original-From: "plaisthos (Code Review)" X-Gerrit-PatchSet: 1 Date: Thu, 30 Nov 2023 16:24:39 +0000 To: flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0 X-Gerrit-Change-Number: 464 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: 431131a90b38c13a293eacdb2d7cbc11ffff6dad References: Message-ID: <11081e6afcc6aa32e3fdf35c8476e9a8f8116eb0-HTML@gerrit.openvpn.net> MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.167.43 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.167.43 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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_AU Message has a valid DKIM or DK signature from author's domain 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1r8jqX-0006u3-T9 Subject: [Openvpn-devel] [M] Change in openvpn[master]: 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: , Reply-To: arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1784006895977132881?= X-GMAIL-MSGID: =?utf-8?q?1784006895977132881?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/464?usp=email to review the following change. Change subject: Replace character_class_debug with proper unit test ...................................................................... Replace character_class_debug with proper unit test Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0 Signed-off-by: Arne Schwabe --- M src/openvpn/buffer.c M src/openvpn/buffer.h M src/openvpn/init.c M tests/unit_tests/openvpn/test_buffer.c 4 files changed, 25 insertions(+), 32 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/464/1 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);