summaryrefslogtreecommitdiffstats
path: root/man7
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-12-03 21:02:35 +0100
committerAlejandro Colomar <alx@kernel.org>2023-12-03 23:07:44 +0100
commit4fbb0290f9f5450289c3e678756b4755a58c590e (patch)
tree1268ac8fb8aa3cf2ba62d67aae5e00b298c54587 /man7
parent11c1741e472c30aa34d59202730588281a1fddfc (diff)
string_copying.7: Fortify source of some functions
By setting the terminating null byte via a stpcpy(dst, "") call, the last byte is also protected by _FORTIFY_SOURCE. Reported-by: "Serge E. Hallyn" <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'man7')
-rw-r--r--man7/string_copying.721
1 files changed, 4 insertions, 17 deletions
diff --git a/man7/string_copying.7 b/man7/string_copying.7
index 5b3d7768a..fc1b5200a 100644
--- a/man7/string_copying.7
+++ b/man7/string_copying.7
@@ -792,7 +792,6 @@ ssize_t
.IR strtcpy "(char *restrict dst, const char *restrict src, size_t dsize)"
{
bool trunc;
- char *p;
size_t dlen, slen;
\&
if (dsize == 0)
@@ -802,8 +801,7 @@ ssize_t
trunc = (slen == dsize);
dlen = slen \- trunc;
\&
- p = mempcpy(dst, src, dlen);
- *p = \[aq]\e0\[aq];
+ stpcpy(mempcpy(dst, src, dlen), "");
return trunc ? \-1 : slen;
}
@@ -824,8 +822,7 @@ char *
return p \- 1;
\&
/* truncation detected */
- end[\-1] = \[aq]\e0\[aq];
- return end;
+ return stpcpy(end\-1, "");
}
\&
.\" ----- EXAMPLES :: Implementations :: zustr2ustp(3) ----------------/
@@ -839,12 +836,7 @@ char *
char *
.IR zustr2stp "(char *restrict dst, const char *restrict src, size_t ssize)"
{
- char *p;
-\&
- p = zustr2ustp(dst, src, ssize);
- *p = \[aq]\e0\[aq];
-\&
- return p;
+ return stpcpy(zustr2ustp(dst, src, ssize), "");
}
\&
.\" ----- EXAMPLES :: Implementations :: ustpcpy(3) -------------------/
@@ -858,12 +850,7 @@ char *
char *
.IR ustr2stp "(char *restrict dst, const char *restrict src, size_t len)"
{
- char *p;
-\&
- p = ustpcpy(dst, src, len);
- *p = \[aq]\e0\[aq];
-\&
- return p;
+ return stpcpy(ustpcpy(dst, src, len), "");
}
.EE
.in