diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-10-12 19:33:03 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-10-12 19:33:03 +0000 |
commit | f7404f6bb9db5ab292047f3129d4d19d53f72ed3 (patch) | |
tree | 5b1d55caa2c4ddf470bdb21c47708c76486cfd95 /src/or | |
parent | 19da1f36c285530d3a52c764ba1c464d3de88487 (diff) | |
download | tor-f7404f6bb9db5ab292047f3129d4d19d53f72ed3.tar tor-f7404f6bb9db5ab292047f3129d4d19d53f72ed3.tar.gz |
Use tor_parse_long in more places
svn:r2453
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/routerparse.c | 34 | ||||
-rw-r--r-- | src/or/test.c | 6 |
2 files changed, 23 insertions, 17 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c index b97390931..be5b899a5 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -778,9 +778,9 @@ routerinfo_t *router_parse_entry_from_string(const char *s, router->addr = 0; if (tok->n_args >= 5) { - router->or_port = atoi(tok->args[2]); - router->socks_port = atoi(tok->args[3]); - router->dir_port = atoi(tok->args[4]); + router->or_port = (uint16_t) tor_parse_long(tok->args[2],10,0,65535,NULL,NULL); + router->socks_port = (uint16_t) tor_parse_long(tok->args[3],10,0,65535,NULL,NULL); + router->dir_port = (uint16_t) tor_parse_long(tok->args[4],10,0,65535,NULL,NULL); ports_set = 1; } } else { @@ -797,9 +797,9 @@ routerinfo_t *router_parse_entry_from_string(const char *s, log_fn(LOG_WARN,"Wrong # of arguments to \"ports\""); goto err; } - router->or_port = atoi(tok->args[0]); - router->socks_port = atoi(tok->args[1]); - router->dir_port = atoi(tok->args[2]); + router->or_port = tor_parse_long(tok->args[0],10,0,65535,NULL,NULL); + router->socks_port = tor_parse_long(tok->args[1],10,0,65535,NULL,NULL); + router->dir_port = tor_parse_long(tok->args[2],10,0,65535,NULL,NULL); 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\""); 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); @@ -824,10 +824,10 @@ routerinfo_t *router_parse_entry_from_string(const char *s, log_fn(LOG_WARN,"Not enough arguments to \"bandwidth\""); goto err; } - router->bandwidthrate = atoi(tok->args[0]); - router->bandwidthburst = atoi(tok->args[1]); + router->bandwidthrate = tor_parse_long(tok->args[0],10,0,INT_MAX,NULL,NULL); + router->bandwidthburst = tor_parse_long(tok->args[1],10,0,INT_MAX,NULL,NULL); 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; } @@ -835,7 +835,7 @@ routerinfo_t *router_parse_entry_from_string(const char *s, if (tok->n_args != 1) { log_fn(LOG_WARN, "Unrecognized number of args on K_UPTIME; skipping."); } 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 in_addr in; char *arg, *address, *mask, *port, *endptr; - int bits; + int bits, ok; 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; } else { 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 == '-') { port = endptr+1; endptr = NULL; - newe->prt_max = (uint16_t) strtol(port, &endptr, 10); - if (*endptr) { + newe->prt_max = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL, + &endptr); + if (*endptr || !newe->prt_max) { log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.", port); } - } else if (*endptr) { + } else if (*endptr || !newe->prt_min) { log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.", port); goto policy_read_failed; diff --git a/src/or/test.c b/src/or/test.c index 4d8bfb8d1..bb0a3db7d 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -664,6 +664,10 @@ test_util() { test_eq(u16, 0); 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. */ smartlist_free(sl); } @@ -919,7 +923,7 @@ test_dir_format() ex2.policy_type = EXIT_POLICY_REJECT; ex2.addr = 18 << 24; ex2.msk = 0xFF000000u; - ex2.prt_min = ex1.prt_max = 24; + ex2.prt_min = ex2.prt_max = 24; ex2.next = NULL; r2.address = "tor.tor.tor"; r2.addr = 0x0a030201u; /* 10.3.2.1 */ |