mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Better bounds checking on parsed ints
svn:r2450
This commit is contained in:
parent
e8748b3fa0
commit
e7241044e8
@ -2052,7 +2052,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
if (colon) {
|
if (colon) {
|
||||||
_address = tor_strndup(addrport, colon-addrport);
|
_address = tor_strndup(addrport, colon-addrport);
|
||||||
_port = atoi(colon+1);
|
_port = atoi(colon+1);
|
||||||
if (_port<1 || _port>65536) {
|
if (_port<1 || _port>65535) {
|
||||||
log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
|
log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
|
||||||
_port = 0;
|
_port = 0;
|
||||||
ok = 0;
|
ok = 0;
|
||||||
|
@ -161,6 +161,10 @@ static rend_service_port_config_t *parse_port_config(const char *string)
|
|||||||
log_fn(LOG_WARN, "Unparseable of missing port in hidden service port configuration.");
|
log_fn(LOG_WARN, "Unparseable of missing port in hidden service port configuration.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (realport < 1 || realport > 65535) {
|
||||||
|
log_fn(LOG_WARN, "Port out of range");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
addr = 0x7F000001u; /* Default to 127.0.0.1 */
|
addr = 0x7F000001u; /* Default to 127.0.0.1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1053,6 +1053,10 @@ router_parse_exit_policy(directory_token_t *tok) {
|
|||||||
bits = (int) strtol(mask, &endptr, 10);
|
bits = (int) strtol(mask, &endptr, 10);
|
||||||
if (!*endptr) {
|
if (!*endptr) {
|
||||||
/* strtol handled the whole mask. */
|
/* strtol handled the whole mask. */
|
||||||
|
if (bits < 0 || bits > 32) {
|
||||||
|
log_fn(LOG_WARN, "Bad number of mask bits on exit policy; rejecting.");
|
||||||
|
goto policy_read_failed;
|
||||||
|
}
|
||||||
newe->msk = ~((1<<(32-bits))-1);
|
newe->msk = ~((1<<(32-bits))-1);
|
||||||
} else if (tor_inet_aton(mask, &in) != 0) {
|
} else if (tor_inet_aton(mask, &in) != 0) {
|
||||||
newe->msk = ntohl(in.s_addr);
|
newe->msk = ntohl(in.s_addr);
|
||||||
@ -1083,6 +1087,10 @@ router_parse_exit_policy(directory_token_t *tok) {
|
|||||||
} else {
|
} else {
|
||||||
newe->prt_max = newe->prt_min;
|
newe->prt_max = newe->prt_min;
|
||||||
}
|
}
|
||||||
|
if (newe->prt_min > newe->prt_max) {
|
||||||
|
log_fn(LOG_WARN,"Insane port range on exit policy; rejecting.");
|
||||||
|
goto policy_read_failed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
in.s_addr = htonl(newe->addr);
|
in.s_addr = htonl(newe->addr);
|
||||||
|
Loading…
Reference in New Issue
Block a user