From owner-cvs-all Thu May 31 12:36:14 2001 Delivered-To: cvs-all@freebsd.org Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id 78A7837B422; Thu, 31 May 2001 12:36:08 -0700 (PDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.11.3/8.11.1) with ESMTP id f4VJZqE94063; Thu, 31 May 2001 13:35:52 -0600 (MDT) (envelope-from imp@harmony.village.org) Message-Id: <200105311935.f4VJZqE94063@harmony.village.org> To: David Malone Subject: Re: cvs commit: src/lib/libc/gen setproctitle.3 syslog.3 src/lib/libc/stdio printf.3 Cc: Kris Kennaway , Garrett Wollman , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org In-reply-to: Your message of "Thu, 31 May 2001 20:13:26 BST." <20010531201326.A68855@walton.maths.tcd.ie> References: <20010531201326.A68855@walton.maths.tcd.ie> <200105252042.f4PKgfu84635@freefall.freebsd.org> <20010526004601.2109A3E2F@bazooka.unixfreak.org> <20010530172131.A60056@FreeBSD.org> <20010530182822.A79068@xor.obsecurity.org> <200105311537.LAA23815@khavrinen.lcs.mit.edu> <20010531115418.B96927@xor.obsecurity.org> Date: Thu, 31 May 2001 13:35:52 -0600 From: Warner Losh 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 In message <20010531201326.A68855@walton.maths.tcd.ie> David Malone writes: : On Thu, May 31, 2001 at 11:54:18AM -0700, Kris Kennaway wrote: : > On Thu, May 31, 2001 at 11:37:31AM -0400, Garrett Wollman wrote: : > > < said: : > > : > > > things like how to use strncpy() properly : > > : > > Mostly, ``don't.'' In almost every case where you think you might : > > want to use strncpy(), strncat() is -- despite its name -- the correct : > > function to use. : > : > Not Helpful. : > : > People use the function and will do so forever, so we should explain : > how to use it correctly. : : AFAIK: strn{cpy,cat} are designed for working on strings which are : stored in fixed sized storage (such as those in struct utmp). These : are not the same as "normal" C strings as they are only nul terminated : if the string is smaller than the storage space. Using strn{cpy,cat} : on normal C strings is just too fiddley to get right all the time. : : In most cases the functions that do what people want are snprintf : (which is in C99) or the strl{cpy,cat} (which atleast *BSD have?). : I dunno what Posix or SUSv? say about these functions. You use strn{cat,cpy} correctly by using them *ONLY* for fixed strings. All other bufer overflow protected thigns should use strl{cpy,cat}. Full stop. We should not encourage people to kludge them for the fixed size buffer case, which is subtly different from the fixed length string case. strl* I think are not standard, but they are useful enough that they should be :-) Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message