IT lexicon › Security › strlcpy

strlcpy

Security På svenska → Updated: 2026-11-08

OpenBSD's string copy that always terminates the destination and tells you if it truncated — and which took the C world a quarter of a century to accept.

C offered strcpy, which writes as far as it likes, and strncpy, which stops at a limit but then leaves the string without a terminating NUL. Todd C. Miller and Theo de Raadt added strlcpy and strlcat to OpenBSD 2.4 in 1998 and presented them at USENIX the following year. They take the full buffer size, always terminate, and return the length of the source, so truncation can be detected with a single comparison.

The other BSDs, Solaris and macOS adopted them quickly. glibc held out for decades — maintainer Ulrich Drepper argued they hid bugs rather than fixing them — before giving in with version 2.38 in 2023. POSIX standardised them in 2024.

← Back to the lexicon