Tobin C. Harding fe072e50be lib/string: Add strscpy_pad() function
[ Upstream commit 458a3bf82df4fe1f951d0f52b1e0c1e9d5a88a3b ]

We have a function to copy strings safely and we have a function to copy
strings and zero the tail of the destination (if source string is
shorter than destination buffer) but we do not have a function to do
both at once.  This means developers must write this themselves if they
desire this functionality.  This is a chore, and also leaves us open to
off by one errors unnecessarily.

Add a function that calls strscpy() then memset()s the tail to zero if
the source string is shorter than the destination buffer.

Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Signed-off-by: Shuah Khan <shuah@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-02-23 14:00:30 +01:00
..
2017-08-15 09:02:08 -07:00
2017-06-09 11:52:07 +02:00
2019-04-20 09:15:07 +02:00
2017-02-24 17:46:57 -08:00
2019-05-21 18:50:21 +02:00
2018-02-16 20:23:04 +01:00
2018-12-08 13:03:35 +01:00
2016-12-06 10:17:03 +02:00
2020-11-05 11:06:58 +01:00
2017-08-15 09:02:07 -07:00