From patchwork Fri Sep 22 16:04:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3366 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7301:2697:b0:d7:3b0f:3938 with SMTP id ha23csp3864471dyb; Fri, 22 Sep 2023 09:05:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHl0M+y3kXw57ZN5+CUvNtbfrchFz0EzPwMoXJPk+ljmt9+7bqTtLa/2R5xiQUV5KUouXsY X-Received: by 2002:a17:902:ec8b:b0:1c4:2b71:7dc9 with SMTP id x11-20020a170902ec8b00b001c42b717dc9mr8874021plg.4.1695398723602; Fri, 22 Sep 2023 09:05:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695398723; cv=none; d=google.com; s=arc-20160816; b=B7G9NP+uGRlxbWAvzag440sVPRvPd5p+5miqZ5YaYiHW39NJsgf2nXq5oJXfjkJ6Af 0+DufoZhJ9w94uEAEifQxD4Yp/q/vHWK+Cz+2+iNJnjPxDa/oVoZMs8uv5dcRJQgBt3w QpfZdVaYvnGOG5kCtHLjG2rQIktPNMGyi2y3BDaK5GgpnsZY7ga1ENJUmXvRZJdnE9XL 4D4+R0AHCGdzA82aMaEs2dHTLNtJ+LNpcJ/VXlHki3eLzo7IgjbbFIp4m3ZidCy4X7Ta nRSvAOujbQ87as8xN5HwAHt2MO5VFq5kSEDnnTOTHK73bBW2JNCne3dO+0HoPYwC6GPZ hu4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:cc: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=9B04C1zHgEcjlx9TTkioa2kKe10r5EKq2YSlE78q5t8=; fh=NK+bcEfKc1ByJiYI2/gKP7k3NGRGiNh2ZjAR/E1gxZk=; b=nyjs96+9eN/YWymH9gej7Np0z+ltkY8KWifBAmfc4+TvuT8P2PdZWVDPZEctDeynGS DqBc/5KwwevxF+nX7nOzTBrrS/2gbZwe25ePHAWrMIWaxxhk208na/nXJYV7U4P15Pqy cHkNKt7UA7i8GmCUi13vLZnSdgtMG9D30O+AHzZXxLYcbmER18qthOlgh9crZEyduos8 QOYPca2WMRbDMO1ihZx3P0zMP7MuaTEbSBXfr86k+7AkAh9rQQHirqAekukZ9IWYqqWM M71APExhM8IeZIrsePSrQq5RhPtC7DJQUS7tvpCuvKjGEIdxO0GGy4qOaFW7pVGq6l2g ZvXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=mm7euXdI; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=kmnMun6h; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=GqoX+FEp; 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 ay6-20020a1709028b8600b001c465e1e219si3936805plb.30.2023.09.22.09.05.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Sep 2023 09:05:23 -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=mm7euXdI; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=kmnMun6h; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=GqoX+FEp; 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 1qjieO-0005wB-Kc; Fri, 22 Sep 2023 16:05:05 +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 1qjieN-0005vZ-Cs for openvpn-devel@lists.sourceforge.net; Fri, 22 Sep 2023 16:05:04 +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:Cc:To:From:Sender:Reply-To: 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=TeLGigTyaKPYZflxFwn1tOY5VFdrJEZk1DyHVoVgIzQ=; b=mm7euXdIrXqr/pZ1bzrtrp2Qug ne405Wpmjjxk9aMix+dU6g9Kp+aBkZpo29sWf66lUv2ptkpOw/gWCKwLL1uG/U8yOI4U0FL6ZXX3I dUVWs3NS8PDa6bqU1JqjDGaESzcUnduS51xXsUF6YuSRGUFkSSZ4rvNXGRk6pgum8mVk=; 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:Cc:To:From:Sender:Reply-To: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=TeLGigTyaKPYZflxFwn1tOY5VFdrJEZk1DyHVoVgIzQ=; b=kmnMun6hqzNv/6gHFaoqCi38M1 nNscMnyd1glkguGPVNx9w/A5/th2xuJ/Xpz3h8/sK/Jz0GFxFiqHdyFb8eEngyJxNNdZNe+hpbxoi mFK6qrhEMpJd2VEsVpoLMd3/0CuG3+semFTHWUohY4eIUeUr6Sz0LlEqV4XNGCefuQlo=; Received: from mout-p-201.mailbox.org ([80.241.56.171]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qjieB-002Rl8-EP for openvpn-devel@lists.sourceforge.net; Fri, 22 Sep 2023 16:04:52 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.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-201.mailbox.org (Postfix) with ESMTPS id 4RscXq0zjqz9ss6; Fri, 22 Sep 2023 18:04:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1695398683; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TeLGigTyaKPYZflxFwn1tOY5VFdrJEZk1DyHVoVgIzQ=; b=GqoX+FEpBW1SICki8ZdKqDchV/aZMpB7O5kRalactk5+SiPXJE2xkfUxHsg6pv0pTJUmds Tg13LYwsWYEBO6BRRkgvnK1n4WOm0vPQghYwecxWOPFfvsRS6boRR7K81OA09YVNNLS9jO 0ofpRQUUxvbHO/ZuLGOWcaJx0PDuwIknAQR96GktwnRTy26g1byiHPL9U5L9sA4M7c177O tisXSloWPZ4v8P73JtQhmmAlRbe4Jxg+mHrB4GMD8uyXlw6wLyBleHH/MSYJsfH1ez0FPr RKX0bifMzrljcrc1xE1xqWg6vM9hcoBz3FvDnSP4Zhika6U7o3zVE0Vx2Iu8sA== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Fri, 22 Sep 2023 18:04:41 +0200 Message-Id: <20230922160441.167168-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 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.171 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_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 Message has at least one valid DKIM or DK signature X-Headers-End: 1qjieB-002Rl8-EP 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: , Cc: Heiko Hund , Antonio Quartulli , Gert Doering Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1777754411633964912?= X-GMAIL-MSGID: =?utf-8?q?1777754411633964912?= 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: Antonio Quartulli Acked-by: Heiko Hund Acked-by: Gert Doering (cherry picked from commit c89a97e449baaf60924a362555d35184f188a646) --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to release/2.6. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/314 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Antonio Quartulli Heiko Hund diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index d099795..7725438 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -316,10 +316,10 @@ { 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); } } }