Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Dec 1996 19:16:12 -0800
From:      Jason Downs <downsj@teeny.org>
To:        J Wunsch <j@uriah.heep.sax.de>
Cc:        marcs@znep.com, dv@kis.ru, freebsd-chat@freebsd.org
Subject:   Re: crontab security hole 
Message-ID:  <199612170316.TAA22717@threadway.teeny.org>
In-Reply-To: Your message of "Mon, 16 Dec 1996 21:51:12 %2B0100." <199612162051.VAA08770@uriah.heep.sax.de> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <199612162051.VAA08770@uriah.heep.sax.de>,
	J Wunsch writes:
>As Jason Downs wrote:
>
>> Haven't any of you ever heard of a very simple and efficient non-stdio
>> routine called, of all things, strncpy()?
>
>Haven't any of you ever heard of the ugly misdesign of strn{cat,cpy}()
>to not delimit your string if it's reaching the end?  I think this is
>violating the principle of least surprise... since they still have the
>`str' in the name, not `mem'.

strncat() always terminates, strncpy() does not if it runs out of space.

Most people terminate the string at the length - 1 after the call to
strncpy(), incase it didn't manage to.  This is sufficient, and avoids
going through any extra processing involved with *printf() as well as
avoiding perhaps needlessly pulling in stdio code.

It's bad programming practice to blindly use snprintf() without considering
your options.  (Just as it's bad to use strncpy() without terminating the
string yourself, or call strncat() with the wrong length.)

-- 
Jason Downs		   (503) 256-8535 -/- (503) 952-3749
downsj@teeny.org  --> teeny.org: Free Software for a Free Internet <--
			     http://www.teeny.org/
	   This ain't no steeenking NetBSD.  http://www.openbsd.org/





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