]> git.ipfire.org Git - thirdparty/openvpn.git/commit
buffer: use memcpy in buf_catrunc
authorFrank Lichtenheld <frank@lichtenheld.com>
Wed, 17 May 2023 11:36:19 +0000 (13:36 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 17 May 2023 17:13:49 +0000 (19:13 +0200)
commitc89a97e449baaf60924a362555d35184f188a646
tree3336dd26d28e3b6c23388516146b2d4a99ab9d13
parenteecf9e9d70955018225e47d96d57da72511c48a0
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: ‘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 <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230517113619.82808-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26683.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/buffer.c