Added checks on topdomain name based on patch from Maxim Bourmistrov

This commit is contained in:
Maxim Bourmistrov 2008-01-07 22:06:09 +00:00 committed by Erik Ekman
parent db58f8de20
commit 7565a2d554
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();
} }