misc/63020: 'utsname' structure field 'nodename' is too short

Cian Synnott cian.synnott at eircom.net
Wed Feb 18 07:20:15 PST 2004


>Number:         63020
>Category:       misc
>Synopsis:       'utsname' structure field 'nodename' is too short
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 18 07:20:14 PST 2004
>Closed-Date:
>Last-Modified:
>Originator:     Cian Synnott
>Release:        FreeBSD 4.9-STABLE i386
>Organization:
eircom.net Computer Incident Response Team
>Environment:
System: FreeBSD hardy.cirt.eircom.net 4.9-STABLE FreeBSD 4.9-STABLE #2: Fri Dec 19 14:38:17 GMT 2003 root at hardy.cirt.eircom.net:/usr/obj/usr/src/sys/HARDY i386


>Description:
	The utsname structure defined in the sys/utsname.h has a maximum of
	32 characters on all fields, including the 'nodename' - the network
	name of the machine. This could reasonably be expected by a
	programmer using the uname() call to be MAXHOSTNAMELEN in length.
	However, long hostnames returned from the wrapped sysctl() are
	truncated.
>How-To-Repeat:
	Compile up something like this:

	#include <stdio.h>
	#include <sys/utsname.h>

	int main()
	{
		struct utsname buf;
		uname (&buf);
		printf ("nodename: %s\n", buf.nodename);
		return 0;
	}

	Then set your hostname to, say
          verylongnameindeed.subdomain.domain.tld
        and run the code. Compare output with that of '/usr/bin/uname', which
        directly calls sysctl().

>Fix:
	Have your program use gethostname() rather than uname() to workaround.
	I expect a proper fix would be alter the utsname structure and uname()
	to use proper lengths on structure fields.


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list