| Summary: | 'utsname' structure field 'nodename' is too short | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Cian Synnott <cian.synnott> |
| Component: | misc | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | CC: | cirt |
| Priority: | Normal | ||
| Version: | 4.9-STABLE | ||
| Hardware: | Any | ||
| OS: | Any | ||
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- State Changed From-To: open->closed Fixed in 5.x |
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().