[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#538763: Description in netcfg/invalid_hostname does not match the code



Package: netcfg
Severity: normal

netcfg/invalid_hostname says:

Template: netcfg/invalid_hostname
Type: error
# :sl2:
_Description: Invalid hostname
 The name "${hostname}" is invalid.
 .
 A valid hostname may contain only the numbers 0-9, the lowercase letters a-z,
 and the minus sign. It must be between 2 and 63 characters long, and may not
 begin or end with a minus sign.

verify_hostname in netcfg-common.c says:

short verify_hostname (char *hname)
{
    static const char *valid_chars =
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.";
    size_t len;
    assert(hname != NULL);

    len = strlen(hname);

    /* Check the hostname for RFC 1123 compliance.  */
    if ((len < 1) ||
        (len > 63) ||
        (strspn(hname, valid_chars) != len) ||
        (hname[len - 1] == '-') ||
        (hname[0] == '-')) {
        return 1;
    }
    else
        return 0;
}

These two do not agree, and I think both have some problems.  The
template should not say that the hostname has a minimum length of 2
characters, and the code should not allow uppercase or dots.

Suggested replacement text for the template:

 The name "${hostname}" is invalid.
 .
 A valid hostname must contain only the numbers 0-9, the lowercase
 letters a-z, and the minus sign. It must be at most 63 characters long,
 and must not begin or end with a minus sign.

The code simply needs to remove the uppercase leters and '.' from
valid_chars.

(RFC 1123, and RFC 952 which it references, seem somewhat ambiguous
about uppercase characters. RFC 1123 says nothing about them, and RFC
952 says "No distinction is made between upper and lower case.". I'd
argue that the code should not permit uppercase, but if it does then the
template needs to change accordingly.)

- Josh Triplett

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.30-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash



Reply to: