Bug 773099

Summary: testHostname() doesn't allow a trailing dot
Product: Red Hat Enterprise Linux 6 Reporter: brian
Component: system-config-networkAssignee: Jan Synacek <jsynacek>
Status: CLOSED ERRATA QA Contact: Branislav Blaškovič <bblaskov>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.1CC: bblaskov, brian.murrell, jsynacek, psklenar
Target Milestone: rcKeywords: Reopened
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-05-10 20:32:35 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1270825    

Description brian 2012-01-10 22:47:43 UTC
Description of problem:

In /usr/share/system-config-network/netconfpkg/NC_functions.py:testHostname() the test does not allow for a trailing dot that is legal for DNS names.  In fact the trailing dot makes a DNS name explicit.


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

# rpm -qf /usr/share/system-config-network/netconfpkg/NC_functions.py
system-config-network-tui-1.6.0.el6.2-1.el6.noarch

How reproducible:

100%

Comment 3 Suzanne Logcher 2012-02-14 23:27:45 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated
in the current release, Red Hat is unfortunately unable to
address this request at this time. Red Hat invites you to
ask your support representative to propose this request, if
appropriate and relevant, in the next release of Red Hat
Enterprise Linux. If you would like it considered as an
exception in the current release, please ask your support
representative.

Comment 5 Jan Synacek 2015-11-27 09:45:37 UTC
What's the real issue here? The hostname can be set to myhost.mydomain without a problem.

Comment 6 Brian J. Murrell 2015-11-27 12:43:44 UTC
(In reply to Jan Synacek from comment #5)
> What's the real issue here? The hostname can be set to myhost.mydomain
> without a problem.

The real problem here is that a domain name with a trailing dot is a legal and valid and _unambiguous_ domain name per RFC 1034 section 3.1:

  Since a complete
  domain name ends with the root label, this leads to a printed form which
  ends in a dot.  We use this property to distinguish between:

     - a character string which represents a complete domain name
       (often called "absolute").  For example, "poneria.ISI.EDU."

     - a character string that represents the starting labels of a
       domain name which is incomplete, and should be completed by
       local software using knowledge of the local domain (often
       called "relative").  For example, "poneria" used in the
       ISI.EDU domain.

To fail when an unambiguous, complete and legal domain name is specified such as is happening in the case of this ticket, is a bug.

What is the real-world problem with this?  I wish you'd have asked me that almost 4 years ago when I originally opened this ticket.

But given that this is a bug and somebody has hit it in the real world and that the fix is absolutely trivial, what is the resistance to fixing it?  Here's the patch:

--- /mnt/centos6.5/usr/share/system-config-network/netconfpkg/NC_functions.py	2010-11-11 15:19:49.000000000 -0500
+++ /tmp/foo	2015-11-27 07:38:52.997684620 -0500
@@ -245,8 +245,8 @@
 
 # we want to compile the regexp just once (not as fast as I expect)
 ip_pattern = re.compile('^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')
-hostname_pattern = re.compile('^([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]|_))?(\.([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]))?)*$')
-length_pattern = re.compile('^[a-zA-Z0-9-_]{1,64}(\.([a-zA-Z0-9-_]{1,64}))*$')
+hostname_pattern = re.compile('^([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]|_))?(\.([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]))?)*\.?$')
+length_pattern = re.compile('^[a-zA-Z0-9-_]{1,64}(\.([a-zA-Z0-9-_]{1,64}))*\.?$')
 def testHostname(hostname):
     # hostname: names separated by '.' every name must be max 63 
     # chars in length and the hostname max length is 255 chars

And the proofs:

$ python
Python 2.7.10 (default, Sep 24 2015, 17:50:09) 
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> hostname_pattern = re.compile('^([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]|_))?(\.([a-zA-Z]|[0-9]|_)(([a-zA-Z]|[0-9]|-|_)*([a-zA-Z]|[0-9]))?)*\.?$')
>>> length_pattern = re.compile('^[a-zA-Z0-9-_]{1,64}(\.([a-zA-Z0-9-_]{1,64}))*\.?$')
>>> length_pattern.match("www.redhat.com")
<_sre.SRE_Match object at 0x7f66f0197938>
>>> length_pattern.match("www.redhat.com.")
<_sre.SRE_Match object at 0x7f66f01979c0>
>>> hostname_pattern.match("www.redhat.com")
<_sre.SRE_Match object at 0x7f66f8dcdeb8>
>>> hostname_pattern.match("www.redhat.com.")
<_sre.SRE_Match object at 0x7f66f8caf410>

Given that it is actually a bug and that I have provided the patch to fix it, I am going to unset the NOTABUG label and reopen this.

Comment 7 Jan Synacek 2015-11-27 12:58:28 UTC
I misread the bug description, hence the confusion.

Comment 8 Jan Synacek 2015-11-27 13:20:05 UTC
In the current release (system-config-network-1.6.0.el6.3), hostname_pattern already contains the trailing dot, but length_pattern doesn't.

Comment 14 Branislav Blaškovič 2016-02-16 11:27:51 UTC
Ok, regexp is ok now, but we are not using this function anywhere in tui so it is just dead code.

Filled another bug (BZ#1308891 so we actually use this function in tui).

Marking this as verified.

Comment 16 errata-xmlrpc 2016-05-10 20:32:35 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2016-0792.html