Strlcpy Slides
Strlcpy Slides
Todd C. Miller
<[email protected]>
Theo de Raadt
<[email protected]>
Slide 1
Overview
• Rationale
• Implementation
Slide 2
Rationale
Slide 3
Why not use strncpy/strncat?
Slide 4
Why Not (continued)
Slide 5
Why Not (continued)
Slide 6
NUL fill in strncpy( ) has a hidden cost
Slide 7
How do strlcpy/strlcat help?
Slide 8
How do strlcpy/strlcat help? (continued)
Slide 9
What strlcpy/strlcat are not...
Slide 10
Simplest implementation of strlcpy()
if (siz) {
if ((n = MIN(slen, siz - 1)))
memcpy(dst, src, n);
dst[n] = ’\0’;
}
return(slen);
}
Slide 11
Simplest implementation of strlcat()
Slide 12
Who’s using strlcpy/strlcat?
• Operating Systems
• Applications
Slide 13
Where to get the code
pub/OpenBSD/lib/libc/string/strlcpy.c
pub/OpenBSD/lib/libc/string/strlcat.c
pub/OpenBSD/lib/libc/string/strlcpy.3
Slide 14