Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Mar 1995 12:06:42 +1000
From:      Bruce Evans <bde@zeta.org.au>
To:        kargl@troutmask.apl.washington.edu, nate@trout.sri.MT.net
Cc:        freebsd-hackers@freefall.cdrom.com
Subject:   Re: install compressed binary patch
Message-ID:  <199503140206.MAA08136@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>> > + 	/*
>> > + 	 * Compression must have been successful, if we get here.
>> > + 	 * So, build a filename for the gzipped file
>> > + 	 */
>> > + 	if (strlen(to_name) < MAXPATHLEN - 3)
>> > + 		strcpy(gz_name, to_name);
>> > + 	strcat(gz_name, ".gz");
>> 
>> What happens if strlen(to_name) >= MAXPATHLEN -3?

>I thought about this for about a second.  The correct thing to do would be
>to declare gz_name as char *, then malloc the needed size of memory,
>then free the memory on exit.  I was a little lazy.

This won't work.  The kernel doesn't allow pathnames longer than MAXPATHLEN
(counting the terminating '\0').  However, you should use dynamic allocation
in portable programs anyway because the maximum path length might depend on
the file system or version of the operating system.  It might be possible
to reduce the path length by cd'ing down the tree.

There is a more serious problem with the limit on the lengths of the
components of the path.  If the final component is longer than NAME_MAX-3,
then you can't append ".gz" to it.  NAME_MAX is 255 for ufs.  You should
use dynamic allocation for path components under FreeBSD because NAME_MAX
_does_ depend on the file system (although the fact that it is defined
says otherwise).  It is 8.3 (sort of) for msdosfs.  Appending ".gz" to the
msdosfs file name "x.y" cannot work.

See the patch sources for the ugly mess required to handle some of these
complications.

Bruce



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