svn commit: trunk/busybox/libbb

Rob Landley rob at landley.net
Mon Feb 20 16:32:32 UTC 2006


On Monday 20 February 2006 5:45 am, Vladimir N. Oleynik wrote:
> vapier at busybox.net wrote:
> > Author: vapier
> > Date: 2006-02-19 15:03:31 -0800 (Sun, 19 Feb 2006)
> > New Revision: 14135
> >
> > Log:
> > rfelker writes in Bug 742: make sure string is null terminated after
> > calling gethostname
>
> http://www.unix.org/single_unix_specification/
>
> The gethostname() function shall return the standard host name for the
> current machine. The namelen argument shall specify the size of the array
> pointed to by the name argument. The returned name shall be
> null-terminated, except that if namelen is an insufficient length to hold
> the host name, then the returned name shall be truncated and it is
> unspecified whether the returned name is null-terminated.

Meaning he made sure that the truncated version would always be null 
terminated.  That was the correct fix.

>  From me:
>
> If gethostname do not set \0 we can usage this function absolutelly,
> we do not know lenght!
>
>
> See 14144 svn revision.

That's broken.  You set the first byte to 0 before you've written anything 
into the array (which accomplishes nothing) and then you overwrite it with 
something that isn't guaranteed to be null terminated.

That makes no sense.  I'm reverting it to the previous version, which was 
correct.

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list