Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Feb 2004 15:07:29 +0000
From:      Cian Synnott <cian.synnott@eircom.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Cc:        cirt@eircom.net
Subject:   misc/63020: 'utsname' structure field 'nodename' is too short
Message-ID:  <20040218150729.GA79940@hardy.cirt.eircom.net>
Resent-Message-ID: <200402181520.i1IFKFWj062607@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help


>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@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:



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