Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 09 Dec 1997 07:41:18 -0800
From:      John Polstra <jdp@polstra.com>
To:        shigio@wafu.netgate.net
Cc:        hackers@freebsd.org
Subject:   Re: [RFC] path converting functions.
Message-ID:  <199712091541.HAA00577@austin.polstra.com>
In-Reply-To: <199712032230.WAA28837@wafu.netgate.net>
References:  <199712032230.WAA28837@wafu.netgate.net>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <199712032230.WAA28837@wafu.netgate.net>,
Shigio Yamaguchi  <shigio@wafu.netgate.net> wrote:

> I've written a set of simple functions to perform conversions between
> an absolute path name and a relative path name.
> 
> Thoughts about this?
> 
> 	o Are there any other functions that will do this?
> 	o Is this useful?
> 	o Is this the correct way to do it?
> 
> ------------------------------------------------------------------------
> 
> abs2rel - make a relative path name from an absolute path name
> 
> 	abs2rel(<original path name>, <base directory>, <result>);
> 
> 	<original path name>	<base directory>	<result>
> 	/usr/src		/etc			../usr/src

Since your functions write into the user-supplied buffer "result",
you should add an argument that specifies how big it is.  See the
gethostname() and snprintf() interfaces, for example.

If you don't add a size argument to limit the number of characters
written into the buffer, you're creating yet another potential
security hole like gets().

An alternative would be to malloc the required amount of space within
your new functions, and return a pointer to it.  If you do that, be
sure to document that the caller is responsible for freeing the space
when he is done with it.

John
--
   John Polstra                                       jdp@polstra.com
   John D. Polstra & Co., Inc.                Seattle, Washington USA
   "Self-knowledge is always bad news."                 -- John Barth



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