Bug 63020

Summary: 'utsname' structure field 'nodename' is too short
Product: Base System Reporter: Cian Synnott <cian.synnott>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: cirt
Priority: Normal    
Version: 4.9-STABLE   
Hardware: Any   
OS: Any   

Description Cian Synnott 2004-02-18 15:20:14 UTC
	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.

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.
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().
Comment 1 netch 2004-03-27 18:38:21 UTC
CS> 	The utsname structure defined in the sys/utsname.h has a maximum of
CS> 	32 characters on all fields, including the 'nodename' - the network
CS> 	name of the machine. This could reasonably be expected by a
CS> 	programmer using the uname() call to be MAXHOSTNAMELEN in length.
CS> 	However, long hostnames returned from the wrapped sysctl() are
CS> 	truncated.

5.* fixes this using variable sized utsname. I think 4.* would not
be fixed because their life is closed to finish.


-netch-
Comment 2 Kris Kennaway freebsd_committer freebsd_triage 2004-04-24 08:56:08 UTC
State Changed
From-To: open->closed

Fixed in 5.x