| Message ID | 20230517084422.70547-1-frank@lichtenheld.com |
|---|---|
| State | Superseded |
| Headers | show
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp1030446dyk;
Wed, 17 May 2023 01:45:34 -0700 (PDT)
X-Google-Smtp-Source:
ACHHUZ4lNo8mqT6CJeFSPn52By81F8YGwgzWUzjR4VNakK0I3714UmdHHZpqQHGc+1yszqF/MQKi
X-Received: by 2002:a5d:8787:0:b0:76f:f462:34d2 with SMTP id
f7-20020a5d8787000000b0076ff46234d2mr3947617ion.14.1684313134365;
Wed, 17 May 2023 01:45:34 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1684313134; cv=none;
d=google.com; s=arc-20160816;
b=d6T0xGVXUF146SDVHPS7CY3a093/gPE2DiR6wqJrE039cHsYX4X2nwuhTrGbDUglWT
lVCqr7VZM4u/uAnjy49jihoha0hwwpTXlRY10csYBAlAa6b1sGtms7AuxyFnuWauSpfm
zXbVWvzMWcEDGAozKy96YG367otOdmtBOTA15zwR00j1kEoaVUL5m0o3NhfuDULWJ2+G
V+0wPmaNz79Oyd9LWr5zFwnIapYBugIcMA9HrPx+6Ni+N4A10sp4IphvyI5h7+HyIgUp
UrQkYgXC6MV0q1KSvsP7++1Wd/DAFy4mh0O6SOJEqAjFfaX93ZzPVKoGcg5Rbd/DcbgN
mv5Q==
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=GiQRUUdxShAp1JbsAodkcWIL+59wL5mKAb48DCRs1bo=;
b=gKOmmaVTP6EfwE74xVmlGa/FeVn0VsW1PJ4xRBOr+MJB4zq8lV1gs1C9a690295D9i
BqpXevtbYRFpvGfgbUw/zXktgi9OtSqmHy7wX48YEoakLcdDXtZbHkhHK7nlCTGrfCnC
3wH23AFTlDJBH03BPKeyNUh1IHA5QEbuwM6e8jC309XIg/SaSdNgrT3lQ/Kz21+Nqa49
cwFi8vQKs7q2jXKct5WHeQnDJ2lhwl4bPMzljm6e0SpGa+SrgR/NUkZb1nFX+qWIXGOI
pYYK+1KbSrDdbWhjRGhswfu9U8onVVz21mnJUMo9F/bclSuTL5+1qyazwpH8X16+rV8q
G7ag==
ARC-Authentication-Results: i=1; mx.google.com;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=gWQUkFRM;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=AObZvQEA;
dkim=neutral (body hash did not verify) header.i=@lichtenheld.com
header.s=MBO0001 header.b=K5frLljj;
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
k4-20020a5e8904000000b0076fe290b78dsi4668985ioj.43.2023.05.17.01.45.33
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Wed, 17 May 2023 01:45:34 -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=gWQUkFRM;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=AObZvQEA;
dkim=neutral (body hash did not verify) header.i=@lichtenheld.com
header.s=MBO0001 header.b=K5frLljj;
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-1.v29.lw.sourceforge.com)
by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95)
(envelope-from <openvpn-devel-bounces@lists.sourceforge.net>)
id 1pzCly-0007s4-7P;
Wed, 17 May 2023 08:44:39 +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 <frank@lichtenheld.com>) id 1pzClx-0007rc-Bo
for openvpn-devel@lists.sourceforge.net;
Wed, 17 May 2023 08:44:38 +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=vjusRKFMWy2lT7chV9Gjkh9vwgHIs/JqJ1OPwbbCpGc=; b=gWQUkFRM5FzbpOjuavz6Ivksqa
bQ1J+SqiOWXieBQOy3JVRYOSol3g9SE/ofezJzAqYPs8Z5ig3FYH2kgSrZ7WS4V/L21sEHFP3IV+H
SxT6zA+Y70dalB3oGl11C/DsBko1HEYFm7hzMm8LD05uGvQ3PyuW0ulZnTE0x+HO63kQ=;
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=vjusRKFMWy2lT7chV9Gjkh9vwgHIs/JqJ1OPwbbCpGc=; b=AObZvQEAquEUQWlNQyhO7+JTuv
6TvRSVfIFvWMIVRjCWP4AnEZseJDc4yx1wsElFs3ss+ia0V+OFSa89MDFlnhfV5orX/ILnWygj08A
3qoEc6bjS7E478Xlll4t/xoRGe5bwUa+hz61Qj6GDcyMNNWF1R74M8I++3Xgsx1MqXCA=;
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 1pzCls-00ArqG-Mo for openvpn-devel@lists.sourceforge.net;
Wed, 17 May 2023 08:44:38 +0000
Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2])
(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 4QLmqq4gvtz9sl2
for <openvpn-devel@lists.sourceforge.net>;
Wed, 17 May 2023 10:44:23 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com;
s=MBO0001; t=1684313063;
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=vjusRKFMWy2lT7chV9Gjkh9vwgHIs/JqJ1OPwbbCpGc=;
b=K5frLljjGJzHcjMHWZ+eEeH2EOhtuB8/QXAwjsl5GDVXOkLje0MSTORHRjtbSUHNqBuCXU
r1accv/66Tzi53sy1pcete0yNtRHCzCQR+ndTWMmelaZIiZf6wkT/mhlszhswclNRuuKiE
ChUDpEe1w8DvpfHbA7f6WpxAmV7VJW8yScQWDcVLKGhDeqL2QLgkET0BVyPjsgtYbaSYjT
dQfZdoxypG/9T2jRbdiPBJEb+M3IaOvyCpMvt9MaoE9aUzhdPJRY+nchqSiJwGImkrex8L
RgCBErVbKpRqsrHSr1nayd1Z/YlcOefDAY9FBX/XrYbPjIaG9Kl7QFdTFVrVIw==
From: Frank Lichtenheld <frank@lichtenheld.com>
To: openvpn-devel@lists.sourceforge.net
Date: Wed, 17 May 2023 10:44:21 +0200
Message-Id: <20230517084422.70547-1-frank@lichtenheld.com>
In-Reply-To: <20230329090447.246561-1-frank@lichtenheld.com>
References: <20230329090447.246561-1-frank@lichtenheld.com>
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.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_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: 1pzCls-00ArqG-Mo
Subject: [Openvpn-devel] [PATCH 1/2 v3] buffer: use memcpy in buf_catrunc
X-BeenThere: openvpn-devel@lists.sourceforge.net
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
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?1766130329265154018?=
|
| Series |
[Openvpn-devel,1/2,v3] buffer: use memcpy in buf_catrunc
|
expand
|
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index d099795b..36b28afb 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; - if (len < buf_forward_capacity_total(buf)) + size_t len = strlen(str); + if (buf_size_valid(len) && (len + 1 < buf_forward_capacity_total(buf))) { - strncpynt((char *)(buf->data + buf->capacity - len), str, len); + memcpy(buf->data + buf->capacity - len - 1, str, len + 1); } } }
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. v2: - make len size_t and change code to avoid any theoretical overflows - remove useless casts v3: - fix off-by-one introduced by v2 %) Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671 Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com> --- src/openvpn/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)