[PATCH] Implement strlcat [BZ#178]

Paul Eggert eggert@cs.ucla.edu
Fri Dec 4 20:20:00 GMT 2015


On 12/04/2015 05:41 AM, Florian Weimer wrote:
> Looks good.

Thanks, I installed the first patch.  Revised versions of the other two 
patches are attached.  Responding to your comments:

> _FORTIFY_SOURCE mostly covers the
> write-to-statically-sized-buffer case.  The manual should not make
> promises the current GCC/glibc combinations cannot deliver.
> _FORTIFY_SOURCE will always be brittle for the more complex cases
> because of the dependency on GCC optimization behavior.
>
> It's also highly application-specific whether a crash (induced by
> _FORTIFY_SOURCE) or truncation (from strncpy or strlcpy) is better.
>

Thanks, good points. I addressed them in the attached patches by 
replacing that paragraph with the following text.

Although some buffer overruns can be prevented by manually replacing
calls to copying functions with calls to truncation functions,
nowadays there are easier and more-reliable automatic techniques that
cause buffer overruns to reliably terminate a program.  These include
GCC's @option{-fsanitize=address} option and, if the destination
buffer is statically sized, defining the @code{_FORTIFY_SOURCE} macro.
Because truncation functions can mask application bugs that would
otherwise be caught by the automatic techniques, these functions
should be used only when the application's underlying logic requires
truncation.


Or perhaps you'd rather not document _FORTIFY_SOURCE at all? I notice 
it's mentioned nowhere in the manual; is that intended? If so, I can 
further revise accordingly.

The attached 2nd patch also alter the proposed strlcpy+strlcat 
documentation as per my more-recent emails. One more thing: the attached 
1st patch also removes the strncat example, as I discovered that it's 
quite misleading and the manual shouldn't be pushing strncat anyway.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Split-large-string-section-add-truncation-advice.patch
Type: text/x-patch
Size: 30711 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20151204/2e945858/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Add-strlcpy-strlcat.patch
Type: text/x-patch
Size: 6684 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20151204/2e945858/attachment-0001.bin>


More information about the Libc-alpha mailing list