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
@@ -66,7 +66,6 @@ inline char *
|
||||
stpecpy(char *dst, char *end, const char *restrict src)
|
||||
{
|
||||
bool trunc;
|
||||
char *p;
|
||||
size_t dsize, dlen, slen;
|
||||
|
||||
if (dst == end)
|
||||
@@ -79,10 +78,7 @@ stpecpy(char *dst, char *end, const char *restrict src)
|
||||
trunc = (slen == dsize);
|
||||
dlen = slen - trunc;
|
||||
|
||||
p = mempcpy(dst, src, dlen);
|
||||
*p = '\0';
|
||||
|
||||
return p + trunc;
|
||||
return stpcpy(mempcpy(dst, src, dlen), "") + trunc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user