]> git.baikalelectronics.ru Git - kernel.git/commit
Fix unefficient call to memset before memcpu in nla_strlcpy.
authorFrancis Laniel <laniel_francis@privacyrequired.com>
Sun, 15 Nov 2020 17:08:04 +0000 (18:08 +0100)
committerJakub Kicinski <kuba@kernel.org>
Mon, 16 Nov 2020 16:08:54 +0000 (08:08 -0800)
commit18c098431d90b769f6051b692ffc09460d8b712e
tree960a5bf156785c6bc904626dd94463d61a07eced
parente3826ae3fee4e84084d03cd57bdaeef182f6b671
Fix unefficient call to memset before memcpu in nla_strlcpy.

Before this commit, nla_strlcpy first memseted dst to 0 then wrote src into it.
This is inefficient because bytes whom number is less than src length are written
twice.

This patch solves this issue by first writing src into dst then fill dst with
0's.
Note that, in the case where src length is higher than dst, only 0 is written.
Otherwise there are as many 0's written to fill dst.

For example, if src is "foo\0" and dst is 5 bytes long, the result will be:
1. "fooGG" after memcpy (G means garbage).
2. "foo\0\0" after memset.

Signed-off-by: Francis Laniel <laniel_francis@privacyrequired.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
lib/nlattr.c