On Fri, Jul 23, 2021 at 03:30:01AM +0200, Vincent Lefevre wrote: > On 2021-07-22 09:11:56 -0700, Kevin J. McCarthy wrote: > > What do you think of using memccpy in the strfcpy macro, > > IMHO, it is better than strncpy, which unnecessarily pads with > null bytes. > > > if it's available, as Ian suggested? > > The Linux memccpy(3) man page says: > > CONFORMING TO > POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD. > > So, for Mutt, it should be available everywhere.
This is probably the best implementation for mutt, and makes sense where e.g. the string is an index format string etc., where truncating the string is normal and expected. If mutt is going to use strfcpy elsewhere, where truncating the string silently might be dangerous, e.g. potentially when programmatically determining a filename, or similar, you should probably have a more secure implementation that doesn't allow you to silently truncate the string. Something like this: int scopy(char *dest, char *src, size_t len) { int rc = snprintf(dest, len, "%s", src); if (rc >= (int)len) return -1; else return rc; } It may make sense to have both... -- Derek D. Martin http://www.pizzashack.org/ GPG Key ID: 0xDFBEAD02 -=-=-=-=- This message is posted from an invalid address. Replying to it will result in undeliverable mail due to spam prevention. Sorry for the inconvenience.
signature.asc
Description: PGP signature