]> git.ipfire.org Git - thirdparty/iproute2.git/commit
utils: strlcpy() and strlcat() don't clobber dst
authorPhil Sutter <phil@nwl.cc>
Wed, 6 Sep 2017 16:51:42 +0000 (18:51 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 7 Sep 2017 22:06:47 +0000 (15:06 -0700)
commit50ea3c64384b1d1bfa9c96de86c21ac8e9fef183
tree7b38c5f9aee9f8b713347add5a3f680ebb7606ac
parent01e5409371270eb59179fb2a63f2827a63368b70
utils: strlcpy() and strlcat() don't clobber dst

As David Laight correctly pointed out, the first version of strlcpy()
modified dst buffer behind the string copied into it. Fix this by
writing NUL to the byte immediately following src string instead of to
the last byte in dst. Doing so also allows to reduce overhead by using
memcpy().

Improve strlcat() by avoiding the call to strlcpy() if dst string is
already full, not just as sanity check.

Signed-off-by: Phil Sutter <phil@nwl.cc>
lib/utils.c