/bin/hostname complains about but still sets invalid hostname

Bug #52335 reported by Florian Diesch
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
hostname (Baltix)
Incomplete
Undecided
Unassigned
hostname (Ubuntu)
Fix Released
Undecided
Unassigned
Dapper
Invalid
Undecided
Unassigned

Bug Description

When trying to set a invalid hostname using /bin/hostname it compalions about the hostname being invalid but still sets it:
diesch@vogon:~% hostname
vogon
diesch@vogon:~% sudo hostname ''
Password:
hostname: the specified hostname is invalid
diesch@vogon:~% hostname

diesch@vogon:~%

After the error msg I didn't expect it to change the hostname so at least the msg should be change to make that clear or (IMHO better) just not set an invalid hostname.

Note: the original reporter indicated the bug was in package 'hostname'; however, that package was not published in Baltix.

Revision history for this message
Ondřej Nový (onovy) wrote :

confirming in ubuntu dapper

Revision history for this message
William Grant (wgrant) wrote :

Erm, no. You just confirmed it in Baltix. Now confirming in Ubuntu.

Changed in hostname:
status: Unconfirmed → Confirmed
Revision history for this message
Adam Niedling (krychek) wrote :

This is still an issue in Intrepid. I'm setting this back to new, maybe it'll get more attention.

Changed in hostname:
status: New → Invalid
status: Confirmed → New
Revision history for this message
Schelfhout (schelf404) wrote :

I was able to reproduce this on Ubuntu 8.10 with package hostname version 2.95.
Results from terminal:

me@:~$ sudo hostname airhead
sudo: unable to resolve host
me@:~$ hostname
airhead
me@:~$ sudo hostname ''
hostname: the specified hostname is invalid
me@:~$ hostname

me@:~$

Contents of /etc/hostname
me@airhead:~$ more /etc/hostname
airhead
me@airhead:~$

Changed in hostname:
status: New → Confirmed
Revision history for this message
Adam Niedling (krychek) wrote :

I really think old "new" bugs get more attention.

Changed in hostname:
status: Confirmed → New
Schelfhout (schelf404)
Changed in hostname:
status: New → Confirmed
Schelfhout (schelf404)
Changed in hostname:
status: Confirmed → New
Revision history for this message
Jeff Anderson (jander99) wrote :

Also confirmed in 8.10, hostname version 2.95 with same method as listed.

Changed in hostname:
status: New → Confirmed
Adam Niedling (krychek)
Changed in hostname:
status: Confirmed → New
status: Confirmed → New
Revision history for this message
Adam Niedling (krychek) wrote :

I decided to look into the source code: http://package-import.ubuntu.com/h/hostname/intrepid/annotate/head%3A/hostname.c

169 if (!check_name(name))
170 warnx("the specified hostname is invalid");
171
172 if (sethostname(name, strlen(name))) {

I'm not really a c expert but this looks like to me that it checks if the hostname is correct but after the error message it just continues to set the hostname no matter what.

Revision history for this message
Gaetan Nadon (memsize) wrote :

Requirements for hostname are as follow:
ASCII letters 'a' through 'z' (case-insensitive), the digits '0' through '9' and the hyphen. Hostname labels cannot begin or end with a hyphen. No other symbols, punctuation characters, or blank spaces are permitted. The length is between 1 and 63 characters. Refer to RFC1034, 1035 and 2181.
Refer to bug 193054 which fixed a similar problem in another package

I have performed a new installation in a VirtualBox using Intrepid. The installer program checks the hostname according to the rules above. The text of the error message, when an invalid hostname is entered, is wrong. It states that "the length should be between 2 and 63."

RFC 1034 states that "Each node has a label, which is zero to 63 octets in length." and that "One label is reserved, and that the null (i.e., zero length) label used for the root." The installer allows me to set a hostname with just one letter, which is correct.

Thanks for reporting this bug. Since this bug has enough information provided for a developer to begin work, I'm going to mark it as confirmed and let them handle it from here. Thanks for taking the time to make Ubuntu better!

Changed in hostname:
status: New → Confirmed
Revision history for this message
Colin Watson (cjwatson) wrote :

hostname (3.03ubuntu1) lucid; urgency=low

  * Merging from Debian Testing, remaining changes:
     - Install Upstart job to set hostname on startup, but do not run it in
       postinst.
     - Build-depend on newer debhelper for Upstart-aware dh_installinit.

 -- Vikram Dhillon <email address hidden> Wed, 10 Mar 2010 19:00:50 +0000

hostname (3.03) unstable; urgency=low

  * Do not use buffer on error return. (Closes: #565634) - thanks to
    Marco d'Itri <email address hidden>

 -- Michael Meskes <email address hidden> Tue, 19 Jan 2010 09:07:56 +0100

hostname (3.02) unstable; urgency=low

  [ Cristian Greco ]
  * bump version to 3.02 for next release.
  * set my new maintainer email address.

  [ Michael Meskes ]
  * Reject invalid hostnames. (LP #52335)
  * Gratiously accept FQ hostnames. While this should not be done
    hostname should still be able to cope with it and print the short
    name as promised in the manpage (LP#389602). (Closes: #563074)
  * Added option to display all ip addresses and all fqdns. (Closes:
    #562830) - thanks to Gábor Gombás <email address hidden>

 -- Michael Meskes <email address hidden> Fri, 15 Jan 2010 13:08:57 +0100

Changed in hostname (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
rusivi2 (rusivi2-deactivatedaccount) wrote :

Thank you for posting this bug.

Is this an issue in Lucid?

Changed in hostname (Baltix):
status: New → Incomplete
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.