Blame SOURCES/dnsmasq-2.66-Tighten_checks_in_legal_hostname.patch

cab8d5
From 7abb69b5dc8dbe369be36bd7bf23c039b036acd1 Mon Sep 17 00:00:00 2001
cab8d5
From: Simon Kelley <simon@thekelleys.org.uk>
cab8d5
Date: Mon, 29 Apr 2013 10:52:16 +0100
cab8d5
Subject: [PATCH] Tighten checks in legal_hostname().
cab8d5
cab8d5
---
cab8d5
 src/util.c | 14 +++++++++-----
cab8d5
 1 file changed, 9 insertions(+), 5 deletions(-)
cab8d5
cab8d5
diff --git a/src/util.c b/src/util.c
cab8d5
index 848e01b..af4031c 100644
cab8d5
--- a/src/util.c
cab8d5
+++ b/src/util.c
cab8d5
@@ -142,19 +142,23 @@ static int check_name(char *in)
cab8d5
 int legal_hostname(char *name)
cab8d5
 {
cab8d5
   char c;
cab8d5
+  int first;
cab8d5
 
cab8d5
   if (!check_name(name))
cab8d5
     return 0;
cab8d5
 
cab8d5
-  for (; (c = *name); name++)
cab8d5
+  for (first = 1; (c = *name); name++, first = 0)
cab8d5
     /* check for legal char a-z A-Z 0-9 - _ . */
cab8d5
     {
cab8d5
       if ((c >= 'A' && c <= 'Z') ||
cab8d5
-	  (c >= 'a' && c <= 'z') ||
cab8d5
-	  (c >= '0' && c <= '9') ||
cab8d5
-	  c == '-' || c == '_')
cab8d5
+	  (c >= 'a' && c <= 'z'))
cab8d5
 	continue;
cab8d5
-      
cab8d5
+
cab8d5
+      if (!first && 
cab8d5
+	  ((c >= '0' && c <= '9') ||
cab8d5
+	   c == '-' || c == '_'))
cab8d5
+	continue;
cab8d5
+
cab8d5
       /* end of hostname part */
cab8d5
       if (c == '.')
cab8d5
 	return 1;
cab8d5
-- 
cab8d5
1.8.1.4
cab8d5