]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Copy one byte less in strncpynt()
authorGert Doering <gert@greenie.muc.de>
Sat, 8 Jun 2019 07:56:22 +0000 (09:56 +0200)
committerGert Doering <gert@greenie.muc.de>
Sun, 9 Jun 2019 09:00:40 +0000 (11:00 +0200)
commitbebd25a0e3a2aba0b1f98463a87b24db6c419a66
tree032f7f0c97f350857989c1b06d20e158893fec91
parentf636d11ff50658c18e0b90b20d641dc54b63e517
Copy one byte less in strncpynt()

While the existing code is not wrong and will never cause an overflow,
it will copy (on a too-long source string) "maxlen" bytes to dest, and
then overwrite the last byte just copied with "0" - which causes a
warning in gcc 9 about filling the target buffer "up to the end,
with no room for a trailing 0 anymore".

Reducing the maximum bytes-to-be-copied to "maxlen -1", because the
last byte will be stamped with 0 anyway.

v2: do not ASSERT() on "maxlen == 0", but move the strncpy() call inside
the if() clause - so "just do nothing" on maxlen == 0, as before.

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20190608075622.11589-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg18502.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/buffer.h