>Synopsis       domains beginning with numbers are incorrectly parsed in 
>dhcpd.conf
>Category:      system  
>Environment:
        System      : OpenBSD 5.5
        Details     : OpenBSD 5.5-stable (GENERIC) #0: Wed Jul  2 01:29:39 PDT 
2014
                         
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC

        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
        A domain component which begins with a number is incorrectly parsed as 
two tokens - the first being a number, and the second a number/name - confusing 
the parser which then expects a dot.

        This leads to a parser configuration error, and then a hostname lookup 
error since it then looks up the wrong hostname. 
>How-To-Repeat:
        Add the following to dhcpd.conf:

option domain-name-servers ns.87k.net;

        dhcpd exits with a parse error. 
>Fix:
        The following patch addresses this issue by appending identifiers 
following numbers to the domain component:

Index: usr.sbin/dhcpd/parse.c
===================================================================
RCS file: /cvs/src/usr.sbin/dhcpd/parse.c,v
retrieving revision 1.17
diff -u -p -r1.17 parse.c
--- usr.sbin/dhcpd/parse.c      18 Dec 2013 20:37:04 -0000      1.17
+++ usr.sbin/dhcpd/parse.c      7 Jul 2014 04:23:15 -0000
@@ -148,15 +148,28 @@ parse_host_name(FILE *cfile)
        do {
                /* Read a token, which should be an identifier. */
                token = next_token(&val, cfile);
-               if (!is_identifier(token) && token != TOK_NUMBER) {
+               if (is_identifier(token)) {
+                       s = strdup(val);
+                       if (s == NULL)
+                               error("can't allocate temp space for 
hostname.");
+               } else if (token == TOK_NUMBER) {
+                       t = strdup(val);
+                       if (t == NULL)
+                               error("can't allocate temp space for hostname");
+                       token = peek_token(&val, cfile);
+                       if (is_identifier(token)) {
+                               token = next_token(&val, cfile);
+                               if (-1 == asprintf(&s, "%s%s", t, val))
+                                       error("can't allocate temp space for 
hostname");
+                               free(t);
+                       } else
+                               s = t;
+               } else {
                        parse_warn("expecting an identifier in hostname");
                        skip_to_semi(cfile);
                        return (NULL);
                }
                /* Store this identifier... */
-               s = strdup(val);
-               if (s == NULL)
-                       error("can't allocate temp space for hostname.");
                c = cons((caddr_t) s, c);
                len += strlen(s) + 1;
                /*

Reply via email to