mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bernd Petrovitsch <bernd@firmix.at>
To: Folkert van Heusden <folkert@vanheusden.com>
Cc: Mitchell Blank Jr <mitch@sfgoth.com>, Willy Tarreau <w@1wt.eu>,
	linux-kernel@vger.kernel.org, kernel-janitors@lists.osdl.org
Subject: Re: strncpy optimalisation? (lib/string.c)
Date: Mon, 11 Dec 2006 00:28:45 +0100	[thread overview]
Message-ID: <1165793325.8998.10.camel@tara.firmix.at> (raw)
In-Reply-To: <20061210213925.GE30197@vanheusden.com>

On Sun, 2006-12-10 at 22:39 +0100, Folkert van Heusden wrote:
> > > Original code completely pads the destination with zeroes,
> > > while yours only adds the last zero. Your code does what
> > > strncpy() is said to do, but maybe there's a particular
> > > reason for it to behave differently in the kernel
> > No, the kernel's strncpy() behaves the same as the one in libc.  Run
> > "man strncpy" if you don't believe me.
> > In the common case where you just want to copy a string and avoid
> > overflow use strlcpy() instead
> 
> Oops you're right! Maybe someone should take a look if the strncpy's
> should be replaced by strlcpy's then because it is (ought to be) faster.

The last time some folks did this (quite automatically) ended in newly
introduced bugs leaking old/stale data from kernel top user space. Alan
Cox went over it (again) and fixed those broken "optimizations".

So whoever wants to do this, look for such issues too.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


      reply	other threads:[~2006-12-10 23:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-10 20:52 Folkert van Heusden
2006-12-10 21:06 ` Willy Tarreau
2006-12-10 21:35   ` Folkert van Heusden
2006-12-10 22:05     ` Mitchell Blank Jr
2006-12-10 21:49       ` Folkert van Heusden
2006-12-10 21:49   ` Mitchell Blank Jr
2006-12-10 21:39     ` Folkert van Heusden
2006-12-10 23:28       ` Bernd Petrovitsch [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=1165793325.8998.10.camel@tara.firmix.at \
    --to=bernd@firmix.at \
    --cc=folkert@vanheusden.com \
    --cc=kernel-janitors@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitch@sfgoth.com \
    --cc=w@1wt.eu \
    /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

all inboxes | Powered by JetHome®