diff options
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 2 | ||||
-rw-r--r-- | src/or/circuit.c | 4 | ||||
-rw-r--r-- | src/or/connection.c | 11 | ||||
-rw-r--r-- | src/or/connection_edge.c | 4 | ||||
-rw-r--r-- | src/or/or.h | 3 | ||||
-rw-r--r-- | src/or/routerlist.c | 52 |
6 files changed, 52 insertions, 24 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 55a4bced99..1ddf9d349d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -433,7 +433,7 @@ int fetch_from_buf_socks(buf_t *buf, socks_request_t *req) { log_fn(LOG_WARN,"socks5: offered methods don't include 'no auth'. Rejecting."); req->replylen = 2; /* 2 bytes of response */ req->reply[0] = 5; /* socks5 reply */ - req->reply[1] = 0xFF; /* reject all methods */ + req->reply[1] = '\xFF'; /* reject all methods */ return -1; } buf_remove_from_front(buf,2+nummethods);/* remove packet from buf */ diff --git a/src/or/circuit.c b/src/or/circuit.c index 3955505179..e0e7aa607c 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -6,7 +6,7 @@ extern or_options_t options; /* command-line and config-file options */ -static int relay_crypt(circuit_t *circ, cell_t *cell, char cell_direction, +static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, crypt_path_t **layer_hint, char *recognized); static connection_t *relay_lookup_conn(circuit_t *circ, cell_t *cell, int cell_direction); static void circuit_free_cpath_node(crypt_path_t *victim); @@ -488,7 +488,7 @@ int circuit_receive_relay_cell(cell_t *cell, circuit_t *circ, } /* wrap this into receive_relay_cell one day */ -static int relay_crypt(circuit_t *circ, cell_t *cell, char cell_direction, +static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction, crypt_path_t **layer_hint, char *recognized) { crypt_path_t *thishop; relay_header_t rh; diff --git a/src/or/connection.c b/src/or/connection.c index 7dc177d4dc..1c7e3cf219 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -258,7 +258,7 @@ int connection_create_listener(char *bindaddress, uint16_t bindport, int type) { return -1; } - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one)); if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) { log_fn(LOG_WARN,"Could not bind to port %u: %s",bindport,strerror(errno)); @@ -418,21 +418,24 @@ int retry_all_connections(void) { if(options.ORPort) { listener_close_if_present(CONN_TYPE_OR_LISTENER); - if(connection_create_listener(options.ORBindAddress, options.ORPort, + if(connection_create_listener(options.ORBindAddress, + (uint16_t) options.ORPort, CONN_TYPE_OR_LISTENER) < 0) return -1; } if(options.DirPort) { listener_close_if_present(CONN_TYPE_DIR_LISTENER); - if(connection_create_listener(options.DirBindAddress, options.DirPort, + if(connection_create_listener(options.DirBindAddress, + (uint16_t) options.DirPort, CONN_TYPE_DIR_LISTENER) < 0) return -1; } if(options.SocksPort) { listener_close_if_present(CONN_TYPE_AP_LISTENER); - if(connection_create_listener(options.SocksBindAddress, options.SocksPort, + if(connection_create_listener(options.SocksBindAddress, + (uint16_t) options.SocksPort, CONN_TYPE_AP_LISTENER) < 0) return -1; } diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index fb4b424278..aa861be847 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -1003,7 +1003,7 @@ static uint32_t client_dns_lookup_entry(const char *address) assert(address); - if (inet_aton(address, &in)) { + if (tor_inet_aton(address, &in)) { log_fn(LOG_DEBUG, "Using static address %s (%08lX)", address, (unsigned long)ntohl(in.s_addr)); return ntohl(in.s_addr); @@ -1039,7 +1039,7 @@ static void client_dns_set_entry(const char *address, uint32_t val) assert(address); assert(val); - if (inet_aton(address, &in)) + if (tor_inet_aton(address, &in)) return; search.address = (char*) address; now = time(NULL); diff --git a/src/or/or.h b/src/or/or.h index 47a3474815..383fc97994 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -85,6 +85,7 @@ #ifdef MS_WINDOWS #include <io.h> #include <process.h> +#include <direct.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #define snprintf _snprintf @@ -349,7 +350,7 @@ struct connection_t { * This is always in the range 0..1<<15-1.*/ /* bandwidth and receiver_bucket only used by ORs in OPEN state: */ - uint32_t bandwidth; /* connection bandwidth. */ + int bandwidth; /* connection bandwidth. */ int receiver_bucket; /* when this hits 0, stop receiving. Every second we * add 'bandwidth' to this, capping it at 10*bandwidth. */ diff --git a/src/or/routerlist.c b/src/or/routerlist.c index f47d829582..4ade31c6f2 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -541,6 +541,36 @@ int router_exit_policy_rejects_all(routerinfo_t *router) { == ADDR_POLICY_REJECTED; } +static time_t parse_time(const char *cp) +{ + struct tm st_tm; + /* XXXX WWWW should be HAVE_STRPTIME */ +#ifndef MS_WINDOWS + if (!strptime(cp, "%Y-%m-%d %H:%M:%S", &st_tm)) { + log_fn(LOG_WARN, "Published time was unparseable"); return 0; + } +#else + unsigned int year=0, month=0, day=0, hour=100, minute=100, second=100; + if (scanf("%u-%u-%u %u:%u:%u", cp, &year, &month, + &day, &hour, &minute, &second) < 6) { + log_fn(LOG_WARN, "Published time was unparseable"); return 0; + } + if (year < 2000 || month < 1 || month > 12 || day < 1 || day > 31 || + hour > 24 || minute > 61 || second > 62) { + log_fn(LOG_WARN, "Published time was nonsensical"); return 0; + } + st_tm.tm_year = year; + st_tm.tm_mon = month; + st_tm.tm_mday = day; + st_tm.tm_hour = hour; + st_tm.tm_min = minute; + st_tm.tm_sec = second; +#endif + return tor_timegm(&st_tm); + +} + + /* Helper function: parse a directory from 's' and, when done, store the * resulting routerlist in *dest, freeing the old value if necessary. * If pkey is provided, we check the directory signature with pkey. @@ -555,7 +585,6 @@ router_get_routerlist_from_directory_impl(const char *str, char signed_digest[128]; routerlist_t *new_dir = NULL; char *versions = NULL; - struct tm published; time_t published_on; char *good_nickname_lst[1024]; int n_good_nicknames = 0; @@ -604,10 +633,9 @@ router_get_routerlist_from_directory_impl(const char *str, } assert(tok->n_args == 1); - if (!strptime(tok->args[0], "%Y-%m-%d %H:%M:%S", &published)) { - log_fn(LOG_WARN, "Published time was unparseable"); goto err; + if (!(published_on = parse_time(tok->args[0]))) { + goto err; } - published_on = tor_timegm(&published); if (!(tok = find_first_by_keyword(tokens, K_RECOMMENDED_SOFTWARE))) { log_fn(LOG_WARN, "Missing recommended-software line from directory."); @@ -781,7 +809,6 @@ routerinfo_t *router_get_entry_from_string(const char *s, char digest[128]; smartlist_t *tokens = NULL, *exit_policy_tokens = NULL; directory_token_t *tok; - struct tm published; int t, i; int ports_set, bw_set; @@ -876,11 +903,8 @@ routerinfo_t *router_get_entry_from_string(const char *s, log_fn(LOG_WARN, "Missing published time"); goto err; } assert(tok->n_args == 1); - if (!strptime(tok->args[0], "%Y-%m-%d %H:%M:%S", &published)) { - log_fn(LOG_WARN, "Published time was unparseable"); goto err; - } - router->published_on = tor_timegm(&published); - + if (!(router->published_on = parse_time(tok->args[0]))) + goto err; if (!(tok = find_first_by_keyword(tokens, K_ONION_KEY))) { log_fn(LOG_WARN, "Missing onion key"); goto err; @@ -1056,7 +1080,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { if (strcmp(address, "*") == 0) { newe->addr = 0; - } else if (inet_aton(address, &in) != 0) { + } else if (tor_inet_aton(address, &in) != 0) { newe->addr = ntohl(in.s_addr); } else { log_fn(LOG_WARN, "Malformed IP %s in exit policy; rejecting.", @@ -1074,7 +1098,7 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { if (!*endptr) { /* strtol handled the whole mask. */ newe->msk = ~((1<<(32-bits))-1); - } else if (inet_aton(mask, &in) != 0) { + } else if (tor_inet_aton(mask, &in) != 0) { newe->msk = ntohl(in.s_addr); } else { log_fn(LOG_WARN, "Malformed mask %s on exit policy; rejecting.", @@ -1087,11 +1111,11 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok) { newe->prt_max = 65535; } else { endptr = NULL; - newe->prt_min = strtol(port, &endptr, 10); + newe->prt_min = (uint16_t) strtol(port, &endptr, 10); if (*endptr == '-') { port = endptr+1; endptr = NULL; - newe->prt_max = strtol(port, &endptr, 10); + newe->prt_max = (uint16_t) strtol(port, &endptr, 10); if (*endptr) { log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.", port); |