Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2002 21:21:19 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Juli Mallett <jmallett@FreeBSD.org>
Cc:        Brooks Davis <brooks@one-eyed-alien.net>, <cvs-committers@FreeBSD.org>, <cvs-all@FreeBSD.org>
Subject:   Re: cvs commit: src/sys/sys libkern.h src/sys/conf files
Message-ID:  <20020903205013.R6846-100000@gamplex.bde.org>
In-Reply-To: <20020902142600.B61674@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 2 Sep 2002, Juli Mallett wrote:

> * De: Brooks Davis <brooks@one-eyed-alien.net> [ Data: 2002-09-02 ]
> 	[ Subjecte: Re: cvs commit: src/sys/sys libkern.h src/sys/conf files ]
> > On Mon, Sep 02, 2002 at 01:16:22PM -0700, Brooks Davis wrote:
> > > brooks      2002/09/02 13:16:22 PDT
> > >
> > >   Modified files:
> > >     sys/sys              libkern.h
> > >     sys/conf             files
> > >   Log:
> > >   Hook up libkern/strlcpy.c and libkern/strlcat.c after repocopy.
> >
> > Intrested parties should start attacking uses of strncat and strncpy.
> > All uses of strncat in the kernel and most uses of strncpy are either
> > wrong or hard to verify and should be converted to strl*.  We should be
> > able to eliminate strncat fairly easily.  strncpy is a bit harder and may
> > be used correctly for fixed width, non-NUL-terminated fields so I
> > suspect we'll be keeping it around.
>
> Why?  If they're not NUL terminated, use memcpy.

(1) memcpy does^shouldn't exist in the kernel.
(2) bcopy is just harder to use correctly if strncpy-like semantics is
    required.  E.g. if bar is an array of char,

	strncpy(bar, foo, sizeof(bar));

    would have to be rewritten to something like:

	len = size_t_min(strlen(foo), sizeof(bar));
	bcopy(foo, bar, len);
	bzero(&bar[len], sizeof(bar) - len));

    or perhaps more clearly and pessimally:

	bzero(bar, sizeof(bar));
	len = size_t_min(strlen(foo), sizeof(bar));
	bcopy(foo, bar, len);

     (This uses the nonexistent interface size_t_min because min and ulmin,
     etc. are hard to use correctly.)

Bruce


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020903205013.R6846-100000>