[PATCH] Implement strlcat [BZ#178]

Paul Eggert eggert@cs.ucla.edu
Thu Dec 10 18:14:00 GMT 2015


On 12/10/2015 08:44 AM, Florian Weimer wrote:
> everything points towards the NetBSD
> implementation being buggy in this regard

"everything"?  Nothing indicates that the NetBSD behavior is a bug; it 
doesn't cause real applications to break. And the NetBSD behavior can 
help catch buggy usage, such as "char *buf = malloc (n); strlcpy (buf, 
src, n - m);" on platforms where NULL points to accessible storage, 
malloc (0) returns NULL, and n happens to be 0.

The main point of strlcpy+strlcat is to guarantee that the output is 
always a null-terminated string that fits.This is what programmers 
understandably expect. This main point is *far* more important than 
obscure details about weird corner cases that should never happen 
anyway. The spec should allow an implementation that guarantees the main 
point, and that terminates the program if the program tries to exploit 
the corner cases by passing bad pointers or null pointers or 
unterminated strings or size-zero buffers that prevent the main point 
from being safely satisfied.



More information about the Libc-alpha mailing list