3 ms·
Todd C. Miller's original paper, strlcpy and strlcat, is a good read about the issues with strncpy and unbounded strcpy. https://www.sudo.ws/todd/papers/strlcp
by brynet 9y ago
Todd C. Miller's original paper, strlcpy and strlcat, is a good read about the issues with strncpy and unbounded strcpy.
https://www.sudo.ws/todd/papers/strlcpy.html https://www.sudo.ws/todd/papers/strlcpy.html (USENIX '99)
Further reading, including EXAMPLEs:
http://man.openbsd.org/strlcpy http://man.openbsd.org/strlcpy
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/string/strlcpy.c?rev=1.15&content-type=text/plain http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/...
Barring quibbles about return values, strlcpy is essentially:
snprintf(dst, sizeof(dst), "%s", src);
A lot of people have been misled by strncpy, when what they really needed was strlcpy:
https://blog.mozilla.org/nfroyd/2013/11/05/the-performance-implications-of-strncpy/ https://blog.mozilla.org/nfroyd/2013/11/05/the-performance-i...
- fnj 9y agoBe aware that the strlcpy paper's timing data comes from another era altogether; an era in which a 25 MHz Motorola 68040 and a 166 MHz Alpha had some slight relevance. Nowadays your phone has 10 to 100 times as much performance. Worrying about a few milliseconds then is now wasting brain cells worrying about microseconds.
- brynet 9y agoNoted above; thanks!