Added checks on topdomain name based on patch from Maxim Bourmistrov

This commit is contained in:
Erik Ekman 2008-01-07 22:06:09 +00:00
parent 98061ccc0e
commit ac46718c16
4 changed files with 33 additions and 4 deletions

View File

@ -111,3 +111,20 @@ read_password(char *buf, size_t len)
strncpy(buf, pwd, len); strncpy(buf, pwd, len);
buf[len-1] = '\0'; buf[len-1] = '\0';
} }
int
check_topdomain(char *str)
{
int i;
if(str[0] == '.') /* special case */
return 1;
for( i = 0; i < strlen(str); i++) {
if( isalpha(str[i]) || isdigit(str[i]) || str[i] == '-' || str[i] == '.' )
continue;
else
return 1;
}
return 0;
}

View File

@ -46,4 +46,6 @@ void do_detach();
void read_password(char*, size_t); void read_password(char*, size_t);
int check_topdomain(char *);
#endif #endif

View File

@ -697,8 +697,13 @@ main(int argc, char **argv)
set_nameserver(nameserv_addr); set_nameserver(nameserv_addr);
if (strlen(topdomain) > 128 || topdomain[0] == '.') { if(strlen(topdomain) <= 128) {
warnx("Use a topdomain max 128 chars long. Do not start it with a dot.\n"); if(check_topdomain(topdomain)) {
warnx("Topdomain contains invalid characters.\n");
usage();
}
} else {
warnx("Use a topdomain max 128 chars long.\n");
usage(); usage();
} }

View File

@ -526,8 +526,13 @@ main(int argc, char **argv)
usage(); usage();
topdomain = strdup(argv[1]); topdomain = strdup(argv[1]);
if (strlen(topdomain) > 128 || topdomain[0] == '.') { if(strlen(topdomain) <= 128) {
warnx("Use a topdomain max 128 chars long. Do not start it with a dot.\n"); if(check_topdomain(topdomain)) {
warnx("Topdomain contains invalid characters.\n");
usage();
}
} else {
warnx("Use a topdomain max 128 chars long.\n");
usage(); usage();
} }