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); } } }