From: Alejandro Colomar via Libc-alpha <libc-alpha@sourceware.org>
To: linux-man@vger.kernel.org
Cc: Alejandro Colomar <alx@kernel.org>,
pkg-shadow-devel@alioth-lists.debian.net,
libc-alpha@sourceware.org
Subject: Re: [PATCH] strcat.3, strncat.3: RIP strncat(3)
Date: Mon, 5 Dec 2022 16:56:07 +0100 [thread overview]
Message-ID: <73f64795-b4fe-956c-c20b-8e2a1fa05929@gmail.com> (raw)
In-Reply-To: <20221205154904.15321-1-alx@kernel.org>
[-- Attachment #1.1: Type: text/plain, Size: 3284 bytes --]
On 12/5/22 16:49, Alejandro Colomar wrote:
> Never use this function. Really.
>
> Cc: <pkg-shadow-devel@alioth-lists.debian.net>
> Cc: <libc-alpha@sourceware.org>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>
> ---
>
> Hi!
>
> To shadow-utils readers, I've seen there are a few uses of strncat(3) in
> shadow-utils. I'll review my current PR about string handling to also
> address this issue.
>
> To glibc readers, please bury this function deep down as if it were
> radioactive waste.
>
> Cheers,
>
> Alex
>
The rendered version of the new manual page for strncpy(3) is:
strncat(3) Library Functions Manual strncat(3)
NAME
strncat - concatenate two strings
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <string.h>
[[deprecated]]
char *strncat(char dest[restrict strlen(.dest) + strnlen(.n) + 1],
const char src[restrict .n],
size_t n);
DESCRIPTION
Note: Never use this function.
For safe string concatenation, see strlcat(3bsd). For copying
or concatenating a string into a fixed‐length buffer with zero‐
ing of the rest, see stpncpy(3).
strncat() appends at most n characters of src to the end of dst.
It always terminates with a null character the string placed in
dest.
A simple implementation of strncat() might be:
char *
strncat(char *dest, const char *src, size_t n)
{
return memcpy(dest + strlen(dest), src, strnlen(src, n));
}
RETURN VALUE
strncat() returns a pointer to the resulting string dest.
ATTRIBUTES
For an explanation of the terms used in this section, see at‐
tributes(7).
┌─────────────────────────────────────┬───────────────┬─────────┐
│Interface │ Attribute │ Value │
├─────────────────────────────────────┼───────────────┼─────────┤
│strncat() │ Thread safety │ MT‐Safe │
└─────────────────────────────────────┴───────────────┴─────────┘
STANDARDS
POSIX.1‐2001, POSIX.1‐2008, C89, C99, SVr4, 4.3BSD.
BUGS
All. Seriously, there’s no use case for this function.
It has a very misleading name. This function has no relation‐
ship with strncpy(3).
Since it doesn’t know the size of the destination buffer, this
function can easily write past the end of the array, being an
open door to all kinds of crackers.
SEE ALSO
strcpy(3), string(3)
Linux man‐pages (unreleased) (date) strncat(3)
--
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2022-12-05 15:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 15:49 [PATCH] strcat.3, strncat.3: RIP strncat(3) Alejandro Colomar via Libc-alpha
2022-12-05 15:56 ` Alejandro Colomar via Libc-alpha [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=73f64795-b4fe-956c-c20b-8e2a1fa05929@gmail.com \
--to=libc-alpha@sourceware.org \
--cc=alx.manpages@gmail.com \
--cc=alx@kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=pkg-shadow-devel@alioth-lists.debian.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).