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); 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

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

View File

@ -690,8 +690,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

@ -490,10 +490,6 @@ main(int argc, char **argv)
break; break;
case 'p': case 'p':
port = atoi(optarg); 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; break;
case 'P': case 'P':
strncpy(password, optarg, sizeof(password)); strncpy(password, optarg, sizeof(password));
@ -520,8 +516,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();
} }
@ -532,11 +533,21 @@ main(int argc, char **argv)
} }
} }
if (mtu == 0) { if (mtu <= 0) {
warnx("Bad MTU given.\n"); warnx("Bad MTU given.\n");
usage(); 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) { if (listen_ip == INADDR_NONE) {
warnx("Bad IP address to listen on.\n"); warnx("Bad IP address to listen on.\n");
usage(); usage();