]> git.ipfire.org Git - people/ms/dnsmasq.git/commitdiff
Tighten checks in legal_hostname().
authorSimon Kelley <simon@thekelleys.org.uk>
Mon, 29 Apr 2013 09:52:16 +0000 (10:52 +0100)
committerSimon Kelley <simon@thekelleys.org.uk>
Mon, 29 Apr 2013 09:52:16 +0000 (10:52 +0100)
src/util.c

index 848e01baaa09dea10e71e907ad7b35d47ea464de..af4031c89f6f7ef9e37036a25cca1bb9f7b15f07 100644 (file)
@@ -142,19 +142,23 @@ static int check_name(char *in)
 int legal_hostname(char *name)
 {
   char c;
+  int first;
 
   if (!check_name(name))
     return 0;
 
-  for (; (c = *name); name++)
+  for (first = 1; (c = *name); name++, first = 0)
     /* check for legal char a-z A-Z 0-9 - _ . */
     {
       if ((c >= 'A' && c <= 'Z') ||
-         (c >= 'a' && c <= 'z') ||
-         (c >= '0' && c <= '9') ||
-         c == '-' || c == '_')
+         (c >= 'a' && c <= 'z'))
        continue;
-      
+
+      if (!first && 
+         ((c >= '0' && c <= '9') ||
+          c == '-' || c == '_'))
+       continue;
+
       /* end of hostname part */
       if (c == '.')
        return 1;