lib/string/: Fortify source of strtcpy(), stpecpy(), and zustr2stp()
By writing the terminating null byte via stpcpy(3), we take advantage of _FORTIFY_SOURCE for the last byte, which was unprotected before this commit. Reported-by: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
72060a2b2b
commit
fc8389331e
@@ -55,7 +55,6 @@ inline ssize_t
|
||||
strtcpy(char *restrict dst, const char *restrict src, size_t dsize)
|
||||
{
|
||||
bool trunc;
|
||||
char *p;
|
||||
size_t dlen, slen;
|
||||
|
||||
if (dsize == 0)
|
||||
@@ -65,8 +64,7 @@ strtcpy(char *restrict dst, const char *restrict src, size_t dsize)
|
||||
trunc = (slen == dsize);
|
||||
dlen = slen - trunc;
|
||||
|
||||
p = mempcpy(dst, src, dlen);
|
||||
*p = '\0';
|
||||
stpcpy(mempcpy(dst, src, dlen), "");
|
||||
|
||||
return trunc ? -1 : slen;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user