public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Horst Schirmeier <horst@schirmeier.com>
To: Eric Sesterhenn <snakebyte@gmx.de>
Cc: LKML <linux-kernel@vger.kernel.org>, bdirks@pacbell.net
Subject: Re: [Patch] Zoran strncpy() cleanup
Date: Tue, 6 Jun 2006 00:01:17 +0200	[thread overview]
Message-ID: <20060605220117.GP7236@quickstop.soohrt.org> (raw)
In-Reply-To: <1149543974.17681.2.camel@alice>

On Mon, 05 Jun 2006, Eric Sesterhenn wrote:
> > Problem is, the strings are (possibly) still not zero-terminated:
> > strncpy() only appends zeroes if src contents are short enough; if they
> > are not, dest is only zero-terminated if dest[sizeof(dest)-1] was zero
> > before.
> > strlcpy() semantics promise more sanity; dest is always zero-terminated
> > (if its size is >= 1), and the size parameter holds total dest size.
> > (See lib/string.c for more details.)
> 
> In all cases there is a memset() which sets the entire structure to
> zero. Since we never write to the last byte with the strncpy() it will
> be null terminated. But if you think strlcpy() is safer for the future,
> i can make you a third patch.

I did not dig in the surrounding code that deeply, no doubt you're right
about the zero termination issue.

I just _personally_ think strlcpy(dest, src, sizeof(*dest)); looks
more sane than strncpy(dest, src, sizeof(*dest)-1);, and it additionally
does not rely on dest being zero-terminated beforehand.

Kind regards,
 Horst

-- 
PGP-Key 0xD40E0E7A

      reply	other threads:[~2006-06-05 22:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-05 20:12 [Patch] Zoran strncpy() cleanup Eric Sesterhenn
2006-06-05 21:02 ` Horst Schirmeier
2006-06-05 21:15   ` Eric Sesterhenn
2006-06-05 21:36     ` Horst Schirmeier
2006-06-05 21:46       ` Eric Sesterhenn
2006-06-05 22:01         ` Horst Schirmeier [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=20060605220117.GP7236@quickstop.soohrt.org \
    --to=horst@schirmeier.com \
    --cc=bdirks@pacbell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snakebyte@gmx.de \
    /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