From owner-cvs-all Tue Sep 3 4:14:16 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8E94D37B400; Tue, 3 Sep 2002 04:14:09 -0700 (PDT) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 44BFA43E6E; Tue, 3 Sep 2002 04:14:08 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from bde.zeta.org.au (bde.zeta.org.au [203.2.228.102]) by mailman.zeta.org.au (8.9.3/8.8.7) with ESMTP id LAA01508; Tue, 3 Sep 2002 11:14:00 GMT Date: Tue, 3 Sep 2002 21:21:19 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Juli Mallett Cc: Brooks Davis , , Subject: Re: cvs commit: src/sys/sys libkern.h src/sys/conf files In-Reply-To: <20020902142600.B61674@FreeBSD.org> Message-ID: <20020903205013.R6846-100000@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Mon, 2 Sep 2002, Juli Mallett wrote: > * De: Brooks Davis [ 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