From patchwork Wed May 17 11:36:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3224 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp1114439dyk; Wed, 17 May 2023 04:36:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7dEWCee7+7A1eITAk921yTT/jAcluTesL8zBgUAXuaqNL4qCLb4P47FE2yEaMHM97eM/g3 X-Received: by 2002:a05:6e02:6d1:b0:325:cc57:df63 with SMTP id p17-20020a056e0206d100b00325cc57df63mr1767471ils.22.1684323419433; Wed, 17 May 2023 04:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684323419; cv=none; d=google.com; s=arc-20160816; b=SciQNs1Rysivx9jVmhnb9Lh/S0E87/kKIiUjxvC9JsL5vPi735OwLRdmHFwKzE5htY ADMvqHk/O1xWkpnVIDRzXlWTM2pasWv5U4u55cFGl2jqi/Ytu8pBB1BfSgEJYvjeCI9G hxQMKTJHztb6nkYrXLvQwZfwyOvGdXIyXujoxZVt1bptLDxc4ZTLJE7PZhMRAmr4G76Z DCrYd45YEjSQM2WKd3wzscOqdhnv1nGwTzhrfEtJRHF0MYIVYEknbtHqroJkceUpZe4f +4AeiIoGZoFG258/WXXKYAQFLDrmrRyMGSHIb+3vmRbaKwfG/2n87LPiskuZTISrrAmy TwYg== 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=vFLgrZSHlSSOgRfd4YFO37z3ZJCW32qU5eGb2hR/VHg=; b=vM/yV89bDHgNt5GksenmfQprWDUJ4m4a0tldiIQ2fCnkOXMd+mP2U1fs8/p0J0MQqL SZ+28hWmXrrY1o8r3ryhJyAeS1nYxnXM2C9OIMDiw+Oo4/XuRi65ORzjm0jnZjs4URyH TYbOyt3lzGj40KSr413cPOe3ZcA5q6gNzUTseb8DlgZl6M82JI+ZKMldcEGl/btDbh7n L0OsJ0cQn+LWIKgBwA8/honZGXLa8WXJAWuzhBxvC/+I6570jYwEau7Ay7nue/xcmO43 rf1CqfzVkh2Bm5k+JRH5iXf5znjLaRCI9MCeMXNgKnl0vZcQZDcgGlbLTeAYM6IrlH1R eOQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YpZSkvgo; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=EoNzDfQQ; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=C9ysUSTY; 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 p4-20020a056e0206c400b003384138045csi169318ils.184.2023.05.17.04.36.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2023 04:36:59 -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=YpZSkvgo; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=EoNzDfQQ; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=C9ysUSTY; 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 1pzFSP-0006Hw-BU; Wed, 17 May 2023 11:36:37 +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 1pzFSN-0006Ho-DD for openvpn-devel@lists.sourceforge.net; Wed, 17 May 2023 11:36:35 +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 :References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YZ0U1x/xXrYdD/TTVS+6POgVR5lbx54j0dRtOrILNzk=; b=YpZSkvgos/AXK0W5JhyUa+SLIt jerCVGXJvo0d257Al+u9oDj9bpQ3E0qvbqt6njUTHLmzGvNNK6VPmEJq+bwKNKZmilxI5DKO2pIsr 8SLbCaL3Ab/IrVNvOhXouz7CDe6yIlWBs7WnFFiQg9MCFmq78qfSJsf7WO1qTjZ+Ng3s=; 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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=YZ0U1x/xXrYdD/TTVS+6POgVR5lbx54j0dRtOrILNzk=; b=EoNzDfQQ1QSHG6PU6ppAqKgSpK 7T2lGUN/18LgJi3+kJIpFVbH7mNiOnFpf6BL249RRn5/2wpYO4oy8Gw/rOy35gl0Rgbswtf287/8n jxxNEG6rDaQCNjZl+o9L90bN5LQdu+71N2ZVytOUF4Zt9IOkDSr1TLKTAeeEz+nXjSF8=; Received: from mout-p-101.mailbox.org ([80.241.56.151]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pzFSI-0001FL-78 for openvpn-devel@lists.sourceforge.net; Wed, 17 May 2023 11:36:35 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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-101.mailbox.org (Postfix) with ESMTPS id 4QLrfD3cqkz9skk for ; Wed, 17 May 2023 13:36:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1684323380; 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: in-reply-to:in-reply-to:references:references; bh=YZ0U1x/xXrYdD/TTVS+6POgVR5lbx54j0dRtOrILNzk=; b=C9ysUSTYJUSN6jk4ocFaTnpkgumEpfWQP3y9VF9L9nDCIt1VrqGSGT80mZGhRddwYBoXsU OP+Rjj9kZesS2sr/IsU/H7jBSHCUQuCNr5Nyg/9eQQxKxHRWsRQGYocQj/cle7iJ4mlSpF Bz4QoWGEQ6sl0OdeaOQJHrssm4kXCyZ8b9jM9pTCv3Y9cZ+oYk1jcz3FJv+Tfy9DDVjtue 5ecTAW4TKVBPjLNhwMUXF0gTVUlqs2UT1j6L8Gqqt6f4CmurBgalViQfsYklSoF3vwqlX+ iEIwriTFLcNG8KSJ0U6EppY1FDhZZH025gPJ2uw7JgVPL4ulitfRuVev9lY5iQ== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Wed, 17 May 2023 13:36:19 +0200 Message-Id: <20230517113619.82808-1-frank@lichtenheld.com> In-Reply-To: <20230517084422.70547-1-frank@lichtenheld.com> References: <20230517084422.70547-1-frank@lichtenheld.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4QLrfD3cqkz9skk 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: 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.151 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_AU Message has a valid DKIM or DK signature from author's domain 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.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1pzFSI-0001FL-78 Subject: [Openvpn-devel] [PATCH 1/2 v4] 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?1766141113648355928?= 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. Also change the type of len to size_t which avoids potential problems with signed overflow. v2: - make len size_t and change code to avoid any theoretical overflows - remove useless casts v3: - fix off-by-one introduced by v2 %) v4: - ignore unsigned overflow to simplify code Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering --- 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..7725438e 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -316,10 +316,10 @@ buf_catrunc(struct buffer *buf, const char *str) { if (buf_forward_capacity(buf) <= 1) { - int len = (int) strlen(str) + 1; + size_t len = strlen(str) + 1; if (len < buf_forward_capacity_total(buf)) { - strncpynt((char *)(buf->data + buf->capacity - len), str, len); + memcpy(buf->data + buf->capacity - len, str, len); } } }