Skip to content
Commit 458a3bf8 authored by Tobin C. Harding's avatar Tobin C. Harding Committed by Shuah Khan
Browse files

lib/string: Add strscpy_pad() function



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: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarTobin C. Harding <tobin@kernel.org>
Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
parent 6b1a4d5b
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment