From: "cron2 (Code Review)" Date: Sat, 23 Sep 2023 09:57:00 +0000 In-Reply-To: References: Reply-To: gert@...1296..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="SnSz0uVaDaA="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[release/2.6]: buffer: use memcpy in buf_catrunc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , d12fk Cc: openvpn-devel --SnSz0uVaDaA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#3) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/314?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by d12fk, Code-Review+2 by ordex Change subject: buffer: use memcpy in buf_catrunc ...................................................................... buffer: use memcpy in buf_catrunc 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: =E2=80=98strncpy=E2=80=99 specified bound depends on the length of the source argument [-Werror=3Dstringop-overflow=3D] 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) Message-Id: <20230922160441.167168-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 085.html Signed-off-by: Gert Doering --- M src/openvpn/buffer.c 1 file changed, 2 insertions(+), 2 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/14/314/3 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) <=3D 1) { - int len =3D (int) strlen(str) + 1; + size_t len =3D 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); } } } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/314?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671 Gerrit-Change-Number: 314 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: d12fk Gerrit-Reviewer: ordex Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --SnSz0uVaDaA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #3 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outda= ted and were removed: Code-Review+2 by d12fk, Code-Review+2 by ordex

buffer: use memcpy in buf_ca=
trunc

Since we use strlen() to determine the length
and then chec= k it ourselves, there is really
no point in using strncpy.

But th= e compiler might complain that we use
the output of strlen() for the len= gth of
strncpy which is usually a sign for bugs:

error: =E2=80=98= strncpy=E2=80=99 specified bound depends
on the length of the source ar= gument
[-Werror=3Dstringop-overflow=3D]

Warning was at least tri= ggered for
mingw-gcc version 10-win32 20220113.

Also change the t= ype of len to size_t
which avoids potential problems with
signed over= flow.

v2:
- make len size_t and change code to avoid any theoret= ical overflows
- remove useless casts
v3:
- fix off-by-one intro= duced by v2 %)
v4:
- ignore unsigned overflow to simplify code
Change-Id: If4a67adac4d2e870fd719b58075d39efcd67c671
Signed-off-by: Fr= ank Lichtenheld <frank@...2641...>
Acked-by: Antonio Quartulli <= ;a@...2181...>
Acked-by: Heiko Hund <heiko@...515...>
Acked-= by: Gert Doering <gert@...1296...>
(cherry picked from commit c89a= 97e449baaf60924a362555d35184f188a646)
Message-Id: <20230922160441.167= 168-1-frank@...2641...>
URL: https://www.mail-archive.com/openvpn-dev= el@lists.sourceforge.net/msg27085.html
Signed-off-by: Gert Doering <g= ert@...1296...>
---
M src/openvpn/buffer.c
1 file changed, 2 in= sertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:294=
18/openvpn refs/changes/14/314/3
diff --git a/src/openvpn/buffer.c =
b/src/openvpn/buffer.c
index d099795..7725438 100644=
--- a/src/openvpn/buffer.c
+++ b/src/openvpn/buff= er.c
@@ -316,10 +316,10 @@
{
if (buf_forward_capacity(buf) <=3D 1)
{

- int len =3D (int)= strlen(str) + 1;
+ = size_t len =3D strlen(str) + 1;
if (len <= buf_forward_capacity_total(buf))
{
- strncpynt((char *)(buf-&= gt;data + buf->capacity - len), str, len);
+ memcpy(buf->data + buf->capacit= y - len, str, len);
}
}
}

To view, visit change 314. To = unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: If4a67adac4d2e870fd719b58075= d39efcd67c671
Gerrit-Change-Number: 314
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: d12fk <heiko@...515...>=
Gerrit-Reviewer: ordex <a@...2181...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--SnSz0uVaDaA=--