Ticket #3573: 0001-libnetworking-rtems_dhcp.c-Fix-improper-hostname-han.2.patch

File 0001-libnetworking-rtems_dhcp.c-Fix-improper-hostname-han.2.patch, 2.2 KB (added by Marçal Comajoan Cara, on 11/13/18 at 22:51:02)

Patch to check the length of the hostname, therefore to solve the bug.

  • cpukit/libnetworking/rtems/rtems_dhcp.c

    From 273deaf62fb0c03337a12dd88f42e680e56d8ab5 Mon Sep 17 00:00:00 2001
    From: Tim Cussins <timcussins@eml.cc>
    Date: Wed, 6 Jan 2016 19:34:39 -0600
    Subject: [PATCH] libnetworking/rtems_dhcp.c: Fix improper hostname handling in
     DHCP request
    
    DHCP requests add the hostname option in dhcp_request_req() - this is cool, except that the dhcp
    spec requires that this option has a length >= 1 char.
    
    Excerpt taken from RFC 2132:
    
       3.14. Host Name Option
    
       This option specifies the name of the client.  The name may or may
       not be qualified with the local domain name (see section 3.17 for the
       preferred way to retrieve the domain name).  See RFC 1035 for
       character set restrictions.
    
       The code for this option is 12, and its minimum length is 1.
    
        Code   Len                 Host Name
       +-----+-----+-----+-----+-----+-----+-----+-----+--
       |  12 |  n  |  h1 |  h2 |  h3 |  h4 |  h5 |  h6 |  ...
       +-----+-----+-----+-----+-----+-----+-----+-----+--
    
    At present, the hostname is added regardless. This appears to trigger a bug in a specific Netgear
    router that causes it's dhcp process to lock up.
    
    closes #1405.
    ---
     cpukit/libnetworking/rtems/rtems_dhcp.c | 16 ++++++++++++----
     1 file changed, 12 insertions(+), 4 deletions(-)
    
    diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c
    index cb6966d..c0c95f5 100644
    a b dhcp_request_req (struct dhcp_packet* call, 
    681681  {
    682682    if (gethostname (hostname, MAXHOSTNAMELEN) == 0)
    683683    {
    684       call->vend[len++] = DHCP_HOST;
    685       call->vend[len++] = strlen (hostname);
    686       strcpy ((char*) &call->vend[len], hostname);
    687       len += strlen (hostname);
     684      /* RFC 2132 Section 3.14 dictates min length for this option is 1 char.
     685         If hostname is zero-length, then let's just not add it */
     686
     687      size_t hostnamelen = strlen (hostname);
     688
     689      if (hostnamelen > 0 && hostnamelen < MAXHOSTNAMELEN)
     690      {
     691        call->vend[len++] = DHCP_HOST;
     692        call->vend[len++] = (uint8_t) hostnamelen;
     693        memcpy (&call->vend[len], hostname, hostnamelen);
     694        len += (int) hostnamelen;
     695      }
    688696    }
    689697    free (hostname, 0);
    690698  }