From patchwork Tue Mar 28 15:12:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3171 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:5492:b0:b2:b40d:92f9 with SMTP id ab18csp659958dyc; Tue, 28 Mar 2023 08:13:14 -0700 (PDT) X-Google-Smtp-Source: AKy350YFVKKYLzFPTfyK+Q+sk8vs0b2qHxAY/VZOrc79PCpoMPvrZQ5IBS10p559B9Nvmlq1IVsF X-Received: by 2002:a17:90b:4ac1:b0:23b:35f6:4ee6 with SMTP id mh1-20020a17090b4ac100b0023b35f64ee6mr16584672pjb.3.1680016394070; Tue, 28 Mar 2023 08:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680016394; cv=none; d=google.com; s=arc-20160816; b=VquLOHAnUESOf9H5xKEcifwW22ACOsHn2ujkrCNokKeGqE1CUx7D9137g9vbVykRpO BEl65hZ1OLG4OXim9ZdpRbtsFL/2ImxVVgr/OqI+9KRNNa3U+retcqLpb7anUioblZZH lxQcpqcG2sfv7vxlAUlo/X2kHETNIVEASUWy/K9q5qTH5Zx6pLPCF0eyjNVegU6wwQCs Ql5bkIboocuRY8DYc+NlTaZ5f8frrD+ilVXpjloHGq8s3FX5ocU1i0HLnBKxWgkC6z2U AZ/0P4qRVBlFD02qfruqGObU+yH/BcKCPmbhpk6eV6a/mu36hYUKTMvqu9DoTyDT8gx3 rCqQ== 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:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature; bh=11h2StWEvKdeYAGnbbrHnnIVb91av3Pd0f05jdH5VP8=; b=QMdMGKfsztlCTbMzEzgIKdritNK7oukysU3FqAA7PaFEHcOu+eQ93A42IQbG62MpzU 2ksBL1qBF+UD9kr9BV3UUHZAkQnRbM6/JZP+/x6yOPCNBcYirewsXPjXdhoCOW5baDD4 csYuYOsbLS1lbHkeKTUzAP55nmBdNyK+qzCkue2cmCvT2ktQLptjoUysGBuiWvdwiEK3 mWym1OFdoktIE7fW2+rvpffyXdYk1WIKwSyPkPEpGRgFi5R3DkJnnvCgeXO7z9ua8r8K wb3rdz7dVzuiVDJdn7BKvenG3/QWx0+pB3RuADgins1kuG9KQN/0Ipfew9O7bgJKWEwE 1Ldg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RMC3brIP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=nMJPpGLt; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=I1jWu0Rc; 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 h16-20020a17090ac39000b0023f043385bcsi8484050pjt.111.2023.03.28.08.13.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Mar 2023 08:13:14 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RMC3brIP; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=nMJPpGLt; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=I1jWu0Rc; 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-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1phB0E-0002Ix-8T; Tue, 28 Mar 2023 15:12:51 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1phB0C-0002Iq-7k for openvpn-devel@lists.sourceforge.net; Tue, 28 Mar 2023 15:12:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version :Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=firJ4Fst9hJrPpPPUzXiqrx8xPHOCerwESyv2HQh+VU=; b=RMC3brIPA5ZIALJt9227ur8Gj7 18QIyqRkkEMlWcWiNCDniqZgSs40Klo66EjxKrx0XY4vmcj4neVJZhSbu4oR4oXtFk1lw693lnWi9 bfN2Gh1nalv6e4mHq9w3CeMiY+YlUkKAg4aBxuHzBwcMXBM7aHofyvzsZOcVRvq71C/s=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=firJ4Fst9hJrPpPPUzXiqrx8xPHOCerwESyv2HQh+VU=; b=n MJPpGLt/I5vnkrs3nTp0QvbzKQwOTaD5vSc+x5OcLbmLWNC8V791cftrgkaNoJ3A9pM2eBtZUBwep 8nyHK4K0XTX1PiX40a4ir0mptFKwPc5az2zL84JVMTxkoRFneLpEG12OD7dVa1lDl+3qSZULjVfoJ EdsFM8ynSbWNGJKo=; Received: from mout-p-202.mailbox.org ([80.241.56.172]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1phB0A-007BKJ-8H for openvpn-devel@lists.sourceforge.net; Tue, 28 Mar 2023 15:12:49 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4PmCpp35shz9sZg for ; Tue, 28 Mar 2023 17:12:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1680016354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=firJ4Fst9hJrPpPPUzXiqrx8xPHOCerwESyv2HQh+VU=; b=I1jWu0Rc8OKBsbnpsilV3tl7Rea2EGj1cbATNrZGsi2vuv1RQSF6CAeID+tmY1bMGhR8xx OLS8XCXULaLLRbxbnp/p7P/bRkrpkyaxWrpg02/wD1giabbQEVBKt3CxpHHeQh12tdQcrc AlHFCIkUQlZcS17S4pl3LTjLcIDPMys5Vu8ZqLBmMPRXabdQYQ07bvAixyvn7cb8wT1y/8 eub6QrTThoLJSofoK/nXSsebSzSkrNK6kcek+gkp72eGUzaNrAoYXtlG8Qb3ymyCGFDy67 TNgjIMO+0CAaSYFC/2VP6RprAuDooKPYVz7sBGN6j464XiVnZpSxllk9kYU8vg== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Tue, 28 Mar 2023 17:12:33 +0200 Message-Id: <20230328151233.217296-1-frank@lichtenheld.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4PmCpp35shz9sZg X-Spam-Score: -0.9 (/) 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: Since we use strlen() to determine the length and then check it ourselves, there is really no point in using strncpy. But the compiler might complain that we use the output of strlen() for the length of strncpy which is usually a sign for bugs: Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-Headers-End: 1phB0A-007BKJ-8H Subject: [Openvpn-devel] [PATCH] buffer: use memcpy in buf_catrunc 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?1761624870130583212?= X-GMAIL-MSGID: =?utf-8?q?1761624870130583212?= Since we use strlen() to determine the length and then check it ourselves, there is really no point in using strncpy. But the compiler might complain that we use the output of strlen() for the length of strncpy which is usually a sign for bugs: error: ‘strncpy’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=] Warning was at least triggered for mingw-gcc version 10-win32 20220113. Signed-off-by: Frank Lichtenheld --- src/openvpn/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index d099795b..de40d690 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -317,9 +317,9 @@ buf_catrunc(struct buffer *buf, const char *str) if (buf_forward_capacity(buf) <= 1) { int len = (int) strlen(str) + 1; - if (len < buf_forward_capacity_total(buf)) + if ((len > 0) && (len < buf_forward_capacity_total(buf))) { - strncpynt((char *)(buf->data + buf->capacity - len), str, len); + memcpy((void *)(buf->data + buf->capacity - len), (void *)str, (size_t)len); } } } From patchwork Wed Mar 29 09:04:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3172 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:5492:b0:b2:b40d:92f9 with SMTP id ab18csp303379dyc; Wed, 29 Mar 2023 02:05:39 -0700 (PDT) X-Google-Smtp-Source: AKy350ba4FHhXE3KmkNB2dbV02nyfgs1LbocbMP51tBGLOasmUk8mpZpjxw5fzesVcEdN72XE5+5 X-Received: by 2002:a17:902:c401:b0:1a1:b9e6:2896 with SMTP id k1-20020a170902c40100b001a1b9e62896mr24738418plk.45.1680080739389; Wed, 29 Mar 2023 02:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680080739; cv=none; d=google.com; s=arc-20160816; b=lLcIieAclmYepPZ2Ud0//ikgjkRuJBVF1bKwZMaA+01RhL/y3VVSD00+MpFGHmg1E7 rnwXa469a6yW3jWWux7PymcLjrZdZjJwix451gc/vVvBOivdRXta9qiIhqGznwrYR0iC 2+QjsZP9YQJdslJFrm07oFYhdK4w+WPXTeDxr1JmFYQRDbbnoNIRmhUncL5Hf1c95qiO ygXW6LgFfEd5glMn3zSlaTsYxl3IQYh/NGBQ4IvFIMQVh9Lw0KMdBSvDYMVmw1lbi2WU kLiu1xtd+3/JLq0CiAR92hMwQVJCyO7CSXVOUzgErXuVl8jpr/vsRxibJs59TxZXMrP6 iZyA== 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=HYBqSCNVjpgVTFnwk+MyvkOhkjmHf/HouzvugrAayp8=; b=JdZPmeD/1TOroMPVax2On6ToW55PX/QREwJoWZ2puMcQZq0jKw/jr3/mr82IN/CLNz SIC+Z8WkZA4XqkJvSCDPMKYoG3p09eOJ+9kJAw8XPh/GcRfhn1rOWjd1rC9Mnf0zKkwf NopeBS/saopMLEeFZtpgPa+ZIaz+kWLtZPnKOsATWYv20fBS2Sj+r+2V/MkOW1sEf3HR zeOwbggciMGQNx4CyNHAwFu0O21bql0YU9o9UA9P4V3hWHzf0pYeDCdrstPXIuzttyKP 1P10uX0afk4bKKK09bMdldj+yy1EjSF7aNXeTCfeqxrd1Y6LAKZtXCMU7eM8MfH7RRqe cPLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=m3sCjzUl; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=myJ9IDRc; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=2F0T8BBx; 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 i185-20020a6387c2000000b0050c104ca623si31280929pge.722.2023.03.29.02.05.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2023 02:05:39 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=m3sCjzUl; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=myJ9IDRc; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=2F0T8BBx; 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-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1phRk4-0002K1-OT; Wed, 29 Mar 2023 09:05:15 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1phRjp-0002Jj-FH for openvpn-devel@lists.sourceforge.net; Wed, 29 Mar 2023 09:05: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: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=YVbk+ij/a2yO7PXp9PbVeyLG4p9VzetqLAdpU8ARDwU=; b=m3sCjzUlxjUnobFUK8oZE5VdSH 3m6RU0eGKDIK4YjExPGA9+AVVSdZCCG6fRebhdpOCBZVxiUBlaOl6I3lLcHVC5NPd8DiUZTcNoHQw /TBNdcEw7scZVT0OzqTp1W8KxFoVtHuGQC6WMB6IIMpGLxp6aan0OicZvFwPtIcLTnw4=; 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=YVbk+ij/a2yO7PXp9PbVeyLG4p9VzetqLAdpU8ARDwU=; b=myJ9IDRcThKjk0HWPemubet+G0 fax2xaLVM3Sz72t54c0yXNXvwEzEdYpdDjQ2+fDp+G0VtpkLt68eFa9lKs39d8+BWUf5zgzJbJV0l 8AECv4xF4czr02Yvc6IN6T25g/CMxHZ+mNBYzMHktc3PKIY1C7gZZXcfyOu5Dy4UpcW8=; Received: from mout-p-103.mailbox.org ([80.241.56.161]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1phRjk-008BfY-MI for openvpn-devel@lists.sourceforge.net; Wed, 29 Mar 2023 09:05:00 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4Pmgc04YNxz9svm for ; Wed, 29 Mar 2023 11:04:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1680080688; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YVbk+ij/a2yO7PXp9PbVeyLG4p9VzetqLAdpU8ARDwU=; b=2F0T8BBxjkoWeypow8NMQVb3TXG9TsO3vLvS7ZvbOp/P7XKB4ir9hSVGWAPaMcIyIMX9c7 waV755QDzTuGcb9y2tbUnFTQ5EiTs1GSdpQkQTmmciqd3GIZl94B88lBEvr92DrA8x5JhW 304opKqdlW2daCOlD4Awmmc3P8O2TYxmFpjrs/5eXN5qzxSYYm3tKllmKCtDokEMplGu77 AM2gMKqFKIFKZcadRSY9kNLHYtC7UrJK1nAEY4vONn7oV5sAmMJq2tSLvukUDuVaybOqzJ YbeDyNFFFHFUnOjk0jiDi2pkEIGrG94UeTL9K8VZZheoZEhMDqyXK+Uq46dnvA== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Wed, 29 Mar 2023 11:04:47 +0200 Message-Id: <20230329090447.246561-2-frank@lichtenheld.com> In-Reply-To: <20230329090447.246561-1-frank@lichtenheld.com> References: <20230328151233.217296-1-frank@lichtenheld.com> <20230329090447.246561-1-frank@lichtenheld.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4Pmgc04YNxz9svm X-Spam-Score: -0.9 (/) 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: Just some very basic tests. Signed-off-by: Frank Lichtenheld --- tests/unit_tests/openvpn/test_buffer.c | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index 9e3b1d2e..5e61fb07 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn [...] Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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 X-Headers-End: 1phRjk-008BfY-MI Subject: [Openvpn-devel] [PATCH 2/2] test_buffer: add tests for buf_catrunc and its caller format_hex_ex 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?1761692341634278240?= X-GMAIL-MSGID: =?utf-8?q?1761692341634278240?= Just some very basic tests. Signed-off-by: Frank Lichtenheld --- tests/unit_tests/openvpn/test_buffer.c | 59 ++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index 9e3b1d2e..5e61fb07 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -56,6 +56,63 @@ test_buffer_strprefix(void **state) assert_int_equal(BLEN(buf), strlen(str)); \ assert_memory_equal(BPTR(buf), str, BLEN(buf)); +static void +test_buffer_printf_catrunc(void **state) +{ + struct gc_arena gc = gc_new(); + struct buffer buf = alloc_buf_gc(16, &gc); + + buf_printf(&buf, "%d", 123); + buf_printf(&buf, "%s", "some text, too long to fit"); + assert_buf_equals_str(&buf, "123some text, t"); + + buf_catrunc(&buf, "..."); + assert_buf_equals_str(&buf, "123some text..."); + + buf_catrunc(&buf, "some other text, much too long to fit"); + assert_buf_equals_str(&buf, "123some text..."); + + buf_catrunc(&buf, "something other"); + assert_buf_equals_str(&buf, "something other"); + + gc_free(&gc); +} + +static void +test_buffer_format_hex_ex(void **state) +{ + const int input_size = 10; + const uint8_t input[] = { + 0x01, 0x00, 0xff, 0x10, 0xff, 0x00, 0xf0, 0x0f, 0x09, 0x0a + }; + char *output; + struct gc_arena gc = gc_new(); + + int maxoutput = 0; + unsigned int blocksize = 5; + char *separator = " "; + output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, &gc); + assert_string_equal(output, "0100ff10ff 00f00f090a"); + + maxoutput = 14; + output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, &gc); + assert_string_equal(output, "0100[more...]"); + + maxoutput = 10; + output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, &gc); + assert_string_equal(output, "[more...]"); + + maxoutput = 9; + output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, &gc); + assert_string_equal(output, "0100ff10"); + + maxoutput = 8; + output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, &gc); + assert_string_equal(output, "0100ff1"); + + gc_free(&gc); +} + struct test_buffer_list_aggregate_ctx { struct buffer_list *empty; struct buffer_list *one_two_three; @@ -267,6 +324,8 @@ main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_buffer_strprefix), + cmocka_unit_test(test_buffer_printf_catrunc), + cmocka_unit_test(test_buffer_format_hex_ex), cmocka_unit_test_setup_teardown(test_buffer_list_aggregate_separator_empty, test_buffer_list_setup, test_buffer_list_teardown),