From 7abb69b5dc8dbe369be36bd7bf23c039b036acd1 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Mon, 29 Apr 2013 10:52:16 +0100 Subject: [PATCH] Tighten checks in legal_hostname(). --- src/util.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/util.c b/src/util.c index 848e01b..af4031c 100644 --- a/src/util.c +++ b/src/util.c @@ -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; -- 1.8.1.4