reapplied maxims patches

This commit is contained in:
Erik Ekman 2008-07-12 11:41:01 +00:00
parent 321781ad85
commit e7de432088
4 changed files with 44 additions and 9 deletions

View file

@ -111,3 +111,20 @@ read_password(char *buf, size_t len)
strncpy(buf, pwd, len);
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

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

View file

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

View file

@ -490,10 +490,6 @@ main(int argc, char **argv)
break;
case 'p':
port = atoi(optarg);
if (port) {
printf("ALERT! Other dns servers expect you to run on port 53.\n");
printf("You must manually forward port 53 to port %d for things to work.\n", port);
}
break;
case 'P':
strncpy(password, optarg, sizeof(password));
@ -520,8 +516,13 @@ main(int argc, char **argv)
usage();
topdomain = strdup(argv[1]);
if (strlen(topdomain) > 128 || topdomain[0] == '.') {
warnx("Use a topdomain max 128 chars long. Do not start it with a dot.\n");
if(strlen(topdomain) <= 128) {
if(check_topdomain(topdomain)) {
warnx("Topdomain contains invalid characters.\n");
usage();
}
} else {
warnx("Use a topdomain max 128 chars long.\n");
usage();
}
@ -532,11 +533,21 @@ main(int argc, char **argv)
}
}
if (mtu == 0) {
if (mtu <= 0) {
warnx("Bad MTU given.\n");
usage();
}
if(port < 1 || port > 65535) {
warnx("Bad port number given.\n");
usage();
}
if (port != 53) {
printf("ALERT! Other dns servers expect you to run on port 53.\n");
printf("You must manually forward port 53 to port %d for things to work.\n", port);
}
if (listen_ip == INADDR_NONE) {
warnx("Bad IP address to listen on.\n");
usage();