Bug 473919 - Hostname validation error
Hostname validation error
Product: Fedora
Classification: Fedora
Component: system-config-network (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Harald Hoyer
Fedora Extras Quality Assurance
: 473858 (view as bug list)
Depends On:
  Show dependency treegraph
Reported: 2008-12-01 08:36 EST by Cong Ma
Modified: 2009-01-07 04:06 EST (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-01-07 04:06:29 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Patch to /usr/share/system-config-network/netconfpkg/NC_functions.py (468 bytes, patch)
2008-12-01 08:36 EST, Cong Ma
no flags Details | Diff

  None (edit)
Description Cong Ma 2008-12-01 08:36:53 EST
Created attachment 325231 [details]
Patch to /usr/share/system-config-network/netconfpkg/NC_functions.py 

Description of problem:
Line 250 in the file /usr/share/system-config-network/netconfpkg/NC_functions.py

The Python regular expression does not match host name parts of a single letter.
Thus, hostnames like "a.example.com" will be rejected when parsing /etc/hosts.

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

How reproducible:

Steps to Reproduce:

Actual results:

Expected results:

Additional info:
I did some research on Google and found an IETF RFC about valid hostnames:
"RFC 1123 -- Requirements for Internet Hosts -- Application and Support".
The part related to hostname is here: http://tools.ietf.org/html/rfc1123#page-13

It made a reference to RFC 952, to which a modification is added. In RFC 952, I found
the original BNF for valid hostname is buried in its spec for DoD internet hostname table.
Namely, it's in the BNFs <hname> (http://tools.ietf.org/html/rfc952#page-5). RFC 1123 made
a revision to allow hostnames to begin with a digit.

Therefore I made a patch in accordance with RFC 1123. The regular expression in the patch
is a direct transliteration of the one found in RFC 952 plus the modification made by
RFC 1123.

There's one thing I'm not sure about though. According to the RFCs, hostnames like
"foo--a-bar.example.com" are valid. However I'm yet to see any real example of hostnames
with consecutive hyphens in it. The original Python code rejects this kinds of names, but
the RFC seems to allow them and so does my patch.

This bug was discovered by the user "ssivil" of FedoraForum.org. Another user "arvinddeshpande"
spotted the offending file, and I made the patch. The original discussion can be found at
http://forums.fedoraforum.org/showthread.php?t=205903 (I also posted the patch in that discussion).

BTW, the RFC use the so-called "Augemented BNF" (http://en.wikipedia.org/wiki/ABNF).
Comment 1 Jiri Moskovcak 2008-12-01 10:24:43 EST
*** Bug 473858 has been marked as a duplicate of this bug. ***
Comment 2 Jiri Moskovcak 2008-12-01 10:35:29 EST
thanks for patch, I'll review the regexp ASAP and make an update with it.

Comment 3 Arvind Deshpande 2008-12-01 12:48:10 EST
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> #'([a-zA-Z]|[0-9])(([a-zA-Z]|[0-9]|-)*([a-zA-Z]|[0-9]))?$')
>>> import re
>>> pat = re.compile('([a-zA-Z]|[0-9])(([a-zA-Z]|[0-9]|-)*([a-zA-Z]|[0-9]))?$')
>>> pat
<_sre.SRE_Pattern object at 0x6d6148>
>>> pat.match('a')
<_sre.SRE_Match object at 0x7ff78cd8>
>>> pat.match('b')
<_sre.SRE_Match object at 0x7ff78d30>
>>> pat.match('9')
<_sre.SRE_Match object at 0x7ff78cd8>
>>> pat.match('a9')
<_sre.SRE_Match object at 0x7ff78d30>
>>> pat.match('a9-')
>>> pat.match('-a9')
>>> pat.match('-a9-')
>>> pat.match('a9')
<_sre.SRE_Match object at 0x7ff78cd8>
>>> pat.match('a9-abc')
<_sre.SRE_Match object at 0x7ff78d30>
>>> pat.match('abc_abcd')
>>> pat.match('9')
<_sre.SRE_Match object at 0x7ff78cd8>
>>> pat.match('-')
>>> pat.match('a-')
>>> pat.match('a-d')
<_sre.SRE_Match object at 0x7ff78d30>
>>> pat.match('a_d')
Comment 5 Fedora Update System 2008-12-17 07:57:53 EST
system-config-network-1.5.95-1.fc10 has been submitted as an update for Fedora 10.
Comment 6 Fedora Update System 2008-12-21 03:24:31 EST
system-config-network-1.5.95-1.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update system-config-network'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2008-11472
Comment 7 Fedora Update System 2009-01-07 04:06:12 EST
system-config-network-1.5.95-1.fc10 has been pushed to the Fedora 10 stable repository.  If problems still persist, please make note of it in this bug report.

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