Ticket #1405: dhcp_hostname_option.patch

File dhcp_hostname_option.patch, 971 bytes (added by Tim Cussins, on 04/24/09 at 12:02:19)

Proposed patch to test hostname length before adding as an option.

  • cpukit/libnetworking/rtems/rtems_dhcp.c

     
    712712  {
    713713    if (gethostname (hostname, MAXHOSTNAMELEN) == 0)
    714714    {
    715       call->vend[len++] = DHCP_HOST;
    716       call->vend[len++] = strlen (hostname);
    717       strcpy ((char*) &call->vend[len], hostname);
    718       len += strlen (hostname);
     715      /* RFC 2132 Section 3.14. dictates min length for this option is 1 char.
     716         If hostname is zero-length, then let's just not add it */
     717
     718      int hostnamelen = strlen(hostname);
     719
     720      if( (hostnamelen > 0) && (hostnamelen < 256) )
     721      {
     722        call->vend[len++] = DHCP_HOST;
     723        call->vend[len++] = (uint8_t) hostnamelen;
     724        strcpy ((char*) &call->vend[len], hostname);
     725        len += hostnamelen;
     726      }
    719727    }
    720728    free (hostname, 0);
    721729  }