Bug 130733 - sysconf(_SC_HOST_NAME_MAX) returns -1, when in fact the maximum hostname size is 64
sysconf(_SC_HOST_NAME_MAX) returns -1, when in fact the maximum hostname size...
Status: CLOSED RAWHIDE
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc (Show other bugs)
3.0
i686 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
http://www.msbit.com/LSB/hostname.c
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-08-23 20:36 EDT by Nick Stoughton
Modified: 2007-11-30 17:07 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-09-30 05:54:57 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Nick Stoughton 2004-08-23 20:36:30 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.2)
Gecko/20040308

Description of problem:
POSIX defines sysconf(_SC_HOST_NAME_MAX) as returning the maximum size
for the system hostname (as set by sethostname()).

In practice, this is limited by the kernel to the size of the utsname
field in which it us stored, which is defined in sys/utsname.h
(actually in bits/utsname.h) as 64.

However, sysconf(_SC_HOST_NAME_MAX) returns -1 and does not alter
errno, indicating that there is no limit on the length of a hostname.

Version-Release number of selected component (if applicable):
glibc-2.3.2-95.20

How reproducible:
Always

Steps to Reproduce:
1. compile and run the program at http://www.msbit.com/LSB/hostname.c


Actual Results:  The program prints -1 (0)


Expected Results:  The program should print 64 (0)


Additional info:
Comment 1 Jakub Jelinek 2004-08-30 06:38:25 EDT
Current CVS glibc returns 64 (since 2004-03-12), but I don't think it is right either.
_POSIX_HOST_NAME_MAX is 255 and the standard says it must be
at least _POSIX_HOST_NAME_MAX.
In the description of {,_SC_}HOST_NAME_MAX there is no word about
sethostname though, just that gethostname never returns a longer
name.  So I think using HOST_NAME_MAX 255 would be ok too.
Comment 2 Nick Stoughton 2004-08-30 13:03:20 EDT
You are right ... sethostname() is not in POSIX at all ... and so I
believe it is theoretically OK to make HOST_NAME_MAX 255. An
application would then know that if it provides a 255 byte buffer to
gethostname(), it will work (or at leat, it won't fail because the
buffer is too small). 

Of course, there is the *suggestion* that you can *set* the hostname
to this length, which you currently can't. I think the current CVS
solution, of returning 64, is the best all round: ask the system how
long a host name can be, set the host name to something no longer, &
it should work (with appropriate privilege).  It would be very weird
if [gs]ethostname() had different max name lengths.

I suppose we could add to the LSB a warning that the lengths are
different for get/sethostname, just as we could add a warning that we
have reduced _POSIX_HOST_NAME_MAX from 255 to 64. [[whichever path you
choose, I will try and ensure that the LSB follows it!]]
Comment 3 Ulrich Drepper 2004-09-30 05:54:57 EDT
The current code uses 64.

Note You need to log in before you can comment on or make changes to this bug.