From: "Peter Eriksen" <s022018@student.dtu.dk>
To: git@vger.kernel.org
Subject: Re: [PATCH] Implement safe_strncpy() as strlcpy() and use it more. [Take 2]
Date: Sun, 11 Jun 2006 15:05:59 +0200 [thread overview]
Message-ID: <20060611130559.GD10430@bohr.gbar.dtu.dk> (raw)
In-Reply-To: <20060611123332.GA3832@robert.daprodeges.fqdn.th-h.de>
On Sun, Jun 11, 2006 at 12:33:32PM +0000, Rocco Rutte wrote:
> Hi,
>
> * Peter Eriksen [06-06-11 14:03:28 +0200] wrote:
>
> >-char *safe_strncpy(char *dest, const char *src, size_t n)
> >+size_t safe_strncpy(char *dest, const char *src, size_t size)
> >{
> >- strncpy(dest, src, n);
> >- dest[n - 1] = '\0';
> >+ size_t ret = strlen(src);
>
> At least FreeBSD's strlen() requires a non-NULL argument, i.e. with
> src==NULL, this will segfault.
>
> If you can ensure that src!=NULL, then it's okay, but the safe_ prefix
> implies something different.
By eyeballing the source code of strlcpy() from FreeBSD and OpenBSD
(which are quite similar), it seems they will segfault if given source
string, which is NULL. So, from what I've understood, safe_strncpy()
is not more unsafe than strlcpy() or the current safe_strncpy(). It does
have different semantics, because the current one pads will NULL, since
it uses strncpy().
Peter
prev parent reply other threads:[~2006-06-11 13:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-11 12:03 [PATCH] Implement safe_strncpy() as strlcpy() and use it more. [Take 2] Peter Eriksen
2006-06-11 12:33 ` Rocco Rutte
2006-06-11 13:05 ` Peter Eriksen [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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060611130559.GD10430@bohr.gbar.dtu.dk \
--to=s022018@student.dtu.dk \
--cc=git@vger.kernel.org \
/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