mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Use tor_parse_long in more places
svn:r2453
This commit is contained in:
parent
19da1f36c2
commit
f7404f6bb9
@ -778,9 +778,9 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
|
|||||||
router->addr = 0;
|
router->addr = 0;
|
||||||
|
|
||||||
if (tok->n_args >= 5) {
|
if (tok->n_args >= 5) {
|
||||||
router->or_port = atoi(tok->args[2]);
|
router->or_port = (uint16_t) tor_parse_long(tok->args[2],10,0,65535,NULL,NULL);
|
||||||
router->socks_port = atoi(tok->args[3]);
|
router->socks_port = (uint16_t) tor_parse_long(tok->args[3],10,0,65535,NULL,NULL);
|
||||||
router->dir_port = atoi(tok->args[4]);
|
router->dir_port = (uint16_t) tor_parse_long(tok->args[4],10,0,65535,NULL,NULL);
|
||||||
ports_set = 1;
|
ports_set = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -797,9 +797,9 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
|
|||||||
log_fn(LOG_WARN,"Wrong # of arguments to \"ports\"");
|
log_fn(LOG_WARN,"Wrong # of arguments to \"ports\"");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
router->or_port = atoi(tok->args[0]);
|
router->or_port = tor_parse_long(tok->args[0],10,0,65535,NULL,NULL);
|
||||||
router->socks_port = atoi(tok->args[1]);
|
router->socks_port = tor_parse_long(tok->args[1],10,0,65535,NULL,NULL);
|
||||||
router->dir_port = atoi(tok->args[2]);
|
router->dir_port = tor_parse_long(tok->args[2],10,0,65535,NULL,NULL);
|
||||||
ports_set = 1;
|
ports_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,7 +811,7 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
|
|||||||
log_fn(LOG_WARN,"Wrong # of arguments to \"dircacheport\"");
|
log_fn(LOG_WARN,"Wrong # of arguments to \"dircacheport\"");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
router->dir_port = atoi(tok->args[0]);
|
router->dir_port = tor_parse_long(tok->args[0],10,1,65535,NULL,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
tok = find_first_by_keyword(tokens, K_BANDWIDTH);
|
tok = find_first_by_keyword(tokens, K_BANDWIDTH);
|
||||||
@ -824,10 +824,10 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
|
|||||||
log_fn(LOG_WARN,"Not enough arguments to \"bandwidth\"");
|
log_fn(LOG_WARN,"Not enough arguments to \"bandwidth\"");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
router->bandwidthrate = atoi(tok->args[0]);
|
router->bandwidthrate = tor_parse_long(tok->args[0],10,0,INT_MAX,NULL,NULL);
|
||||||
router->bandwidthburst = atoi(tok->args[1]);
|
router->bandwidthburst = tor_parse_long(tok->args[1],10,0,INT_MAX,NULL,NULL);
|
||||||
if(tok->n_args > 2)
|
if(tok->n_args > 2)
|
||||||
router->bandwidthcapacity = atoi(tok->args[2]);
|
router->bandwidthcapacity = tor_parse_long(tok->args[2],10,0,INT_MAX,NULL,NULL);
|
||||||
bw_set = 1;
|
bw_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -835,7 +835,7 @@ routerinfo_t *router_parse_entry_from_string(const char *s,
|
|||||||
if (tok->n_args != 1) {
|
if (tok->n_args != 1) {
|
||||||
log_fn(LOG_WARN, "Unrecognized number of args on K_UPTIME; skipping.");
|
log_fn(LOG_WARN, "Unrecognized number of args on K_UPTIME; skipping.");
|
||||||
} else {
|
} else {
|
||||||
router->uptime = atol(tok->args[0]);
|
router->uptime = tor_parse_long(tok->args[0],10,0,LONG_MAX,NULL,NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,7 +1003,7 @@ router_parse_exit_policy(directory_token_t *tok) {
|
|||||||
struct exit_policy_t*newe;
|
struct exit_policy_t*newe;
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
char *arg, *address, *mask, *port, *endptr;
|
char *arg, *address, *mask, *port, *endptr;
|
||||||
int bits;
|
int bits, ok;
|
||||||
|
|
||||||
tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
|
tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT);
|
||||||
|
|
||||||
@ -1071,16 +1071,18 @@ router_parse_exit_policy(directory_token_t *tok) {
|
|||||||
newe->prt_max = 65535;
|
newe->prt_max = 65535;
|
||||||
} else {
|
} else {
|
||||||
endptr = NULL;
|
endptr = NULL;
|
||||||
newe->prt_min = (uint16_t) strtol(port, &endptr, 10);
|
newe->prt_min = (uint16_t) tor_parse_long(port, 10, 1, 65535,
|
||||||
|
NULL, &endptr);
|
||||||
if (*endptr == '-') {
|
if (*endptr == '-') {
|
||||||
port = endptr+1;
|
port = endptr+1;
|
||||||
endptr = NULL;
|
endptr = NULL;
|
||||||
newe->prt_max = (uint16_t) strtol(port, &endptr, 10);
|
newe->prt_max = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
|
||||||
if (*endptr) {
|
&endptr);
|
||||||
|
if (*endptr || !newe->prt_max) {
|
||||||
log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
|
log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
|
||||||
port);
|
port);
|
||||||
}
|
}
|
||||||
} else if (*endptr) {
|
} else if (*endptr || !newe->prt_min) {
|
||||||
log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
|
log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
|
||||||
port);
|
port);
|
||||||
goto policy_read_failed;
|
goto policy_read_failed;
|
||||||
|
@ -664,6 +664,10 @@ test_util() {
|
|||||||
test_eq(u16, 0);
|
test_eq(u16, 0);
|
||||||
tor_free(cp);
|
tor_free(cp);
|
||||||
|
|
||||||
|
/* Test tor_parse_long. */
|
||||||
|
test_eq(10L, tor_parse_long("10",10,0,100,NULL,NULL));
|
||||||
|
test_eq(0L, tor_parse_long("10",10,50,100,NULL,NULL));
|
||||||
|
|
||||||
/* XXXX test older functions. */
|
/* XXXX test older functions. */
|
||||||
smartlist_free(sl);
|
smartlist_free(sl);
|
||||||
}
|
}
|
||||||
@ -919,7 +923,7 @@ test_dir_format()
|
|||||||
ex2.policy_type = EXIT_POLICY_REJECT;
|
ex2.policy_type = EXIT_POLICY_REJECT;
|
||||||
ex2.addr = 18 << 24;
|
ex2.addr = 18 << 24;
|
||||||
ex2.msk = 0xFF000000u;
|
ex2.msk = 0xFF000000u;
|
||||||
ex2.prt_min = ex1.prt_max = 24;
|
ex2.prt_min = ex2.prt_max = 24;
|
||||||
ex2.next = NULL;
|
ex2.next = NULL;
|
||||||
r2.address = "tor.tor.tor";
|
r2.address = "tor.tor.tor";
|
||||||
r2.addr = 0x0a030201u; /* 10.3.2.1 */
|
r2.addr = 0x0a030201u; /* 10.3.2.1 */
|
||||||
|
Loading…
Reference in New Issue
Block a user