[PATCH 1/2] Implement strlcpy and strlcat [BZ #178]

Alejandro Colomar alx.manpages@gmail.com
Thu Apr 6 22:15:48 GMT 2023


Hi Florian,

On 4/6/23 23:35, Florian Weimer wrote:
[...]

> 
> OpenBSD alludes to this as well:
> 
> | strlcat() appends string src to the end of dst. It will append at
> | most dstsize - strlen(dst) - 1 characters. It will then
> | NUL-terminate, unless dstsize is 0 or the original dst string was
> | longer than dstsize (in practice this should not happen as it means
> | that either dstsize is incorrect or that dst is not a proper
> | string).

Hmm, that text replaced the one I quoted (which has been kept in
libbsd's page), in this commit:


commit 5df0f979487d1950d0e8885be683158e55ff4ae3
Author: deraadt <deraadt@openbsd.org>
Date:   Mon Apr 2 17:33:11 2012 +0000

    simplify the strlcpy/strlcat manual page substantially.  do less
    explaining of "what a C string is", and make it more clear that these
    functiosn BEHAVE EXACTLY LIKE snprintf with "%s"!  (anyone who wants
    to write a 'strlcpy considered harmful' paper should probably write a
    'strlcpy and snprintf considered harmful' paper instead).
    
    note to those from other projects reading this commit message: It would
    be very good if this new manual was picked up in your project.
    
    ok jmc millert krw

> 
> <https://man.openbsd.org/strlcat>
> 
> So I think we should be calling strnlen here.  If we call strlen
> instead, we'd have to bound the result.

Hmm, it depends on what we decide to do with the conditional right
after the strnlen(3) call.  Either we remove the conditional, or
transform strnlen(3) to strlen(3), but not both.  I guess strnlen(3)
is more readable, since it's just one line.

Anyway, as I said, I would just burn it all and make this function
be a two-liner.  :)

Cheers,
Alex

> 
> Thanks,
> Florian

-- 
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20230407/05d100bf/attachment.sig>


More information about the Libc-alpha mailing list