mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-19 09:50:29 +01:00
Merge branch 'bug18902_squashed'
This commit is contained in:
commit
a8676b1ede
3
changes/bug19578
Normal file
3
changes/bug19578
Normal file
@ -0,0 +1,3 @@
|
||||
o Minor bugfixes (logging):
|
||||
- When logging a directory ownership mismatch, log the owning username
|
||||
correctly. Fixes bug 19578; bugfix on 0.2.2.29-beta.
|
@ -1810,6 +1810,7 @@ if test "x$enable_gcc_warnings_advisory" != "xno"; then
|
||||
-Wselector-type-mismatch
|
||||
-Wsentinel
|
||||
-Wserialized-diagnostics
|
||||
-Wshadow
|
||||
-Wshift-count-negative
|
||||
-Wshift-count-overflow
|
||||
-Wshift-negative-value
|
||||
|
@ -2320,13 +2320,14 @@ check_private_dir,(const char *dirname, cpd_check_t check,
|
||||
running_gid = getgid();
|
||||
}
|
||||
if (st.st_uid != running_uid) {
|
||||
const struct passwd *pw = NULL;
|
||||
const struct passwd *pw_uid = NULL;
|
||||
char *process_ownername = NULL;
|
||||
|
||||
pw = tor_getpwuid(running_uid);
|
||||
process_ownername = pw ? tor_strdup(pw->pw_name) : tor_strdup("<unknown>");
|
||||
pw_uid = tor_getpwuid(running_uid);
|
||||
process_ownername = pw_uid ? tor_strdup(pw_uid->pw_name) :
|
||||
tor_strdup("<unknown>");
|
||||
|
||||
pw = tor_getpwuid(st.st_uid);
|
||||
pw_uid = tor_getpwuid(st.st_uid);
|
||||
|
||||
log_warn(LD_FS, "%s is not owned by this user (%s, %d) but by "
|
||||
"%s (%d). Perhaps you are running Tor as the wrong user?",
|
||||
@ -3840,9 +3841,9 @@ format_win_cmdline_argument(const char *arg)
|
||||
formatted_arg[i++] = '"';
|
||||
|
||||
/* Add characters */
|
||||
SMARTLIST_FOREACH(arg_chars, char*, c,
|
||||
SMARTLIST_FOREACH(arg_chars, char*, ch,
|
||||
{
|
||||
formatted_arg[i++] = *c;
|
||||
formatted_arg[i++] = *ch;
|
||||
});
|
||||
|
||||
/* Add trailing quote */
|
||||
|
@ -1901,8 +1901,8 @@ channel_tls_process_certs_cell(var_cell_t *cell, channel_tls_t *chan)
|
||||
}
|
||||
|
||||
err:
|
||||
for (unsigned i = 0; i < ARRAY_LENGTH(certs); ++i) {
|
||||
tor_x509_cert_free(certs[i]);
|
||||
for (unsigned u = 0; u < ARRAY_LENGTH(certs); ++u) {
|
||||
tor_x509_cert_free(certs[u]);
|
||||
}
|
||||
certs_cell_free(cc);
|
||||
#undef ERR
|
||||
|
@ -1565,7 +1565,7 @@ choose_good_exit_server_general(int need_uptime, int need_capacity)
|
||||
int n_best_support=0;
|
||||
const or_options_t *options = get_options();
|
||||
const smartlist_t *the_nodes;
|
||||
const node_t *node=NULL;
|
||||
const node_t *selected_node=NULL;
|
||||
|
||||
connections = get_connection_array();
|
||||
|
||||
@ -1692,7 +1692,7 @@ choose_good_exit_server_general(int need_uptime, int need_capacity)
|
||||
smartlist_add(supporting, (void*)node);
|
||||
});
|
||||
|
||||
node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
||||
selected_node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
||||
smartlist_free(supporting);
|
||||
} else {
|
||||
/* Either there are no pending connections, or no routers even seem to
|
||||
@ -1730,8 +1730,8 @@ choose_good_exit_server_general(int need_uptime, int need_capacity)
|
||||
}
|
||||
} SMARTLIST_FOREACH_END(node);
|
||||
|
||||
node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
||||
if (node)
|
||||
selected_node = node_sl_choose_by_bandwidth(supporting, WEIGHT_FOR_EXIT);
|
||||
if (selected_node)
|
||||
break;
|
||||
smartlist_clear(supporting);
|
||||
/* If we reach this point, we can't actually support any unhandled
|
||||
@ -1745,9 +1745,9 @@ choose_good_exit_server_general(int need_uptime, int need_capacity)
|
||||
}
|
||||
|
||||
tor_free(n_supported);
|
||||
if (node) {
|
||||
log_info(LD_CIRC, "Chose exit server '%s'", node_describe(node));
|
||||
return node;
|
||||
if (selected_node) {
|
||||
log_info(LD_CIRC, "Chose exit server '%s'", node_describe(selected_node));
|
||||
return selected_node;
|
||||
}
|
||||
if (options->ExitNodes) {
|
||||
log_warn(LD_CIRC,
|
||||
|
@ -3489,10 +3489,10 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
||||
}
|
||||
|
||||
if (server_mode(options)) {
|
||||
char *msg = NULL;
|
||||
if (have_enough_mem_for_dircache(options, 0, &msg)) {
|
||||
log_warn(LD_CONFIG, "%s", msg);
|
||||
tor_free(msg);
|
||||
char *dircache_msg = NULL;
|
||||
if (have_enough_mem_for_dircache(options, 0, &dircache_msg)) {
|
||||
log_warn(LD_CONFIG, "%s", dircache_msg);
|
||||
tor_free(dircache_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4823,7 +4823,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
{
|
||||
or_options_t *oldoptions, *newoptions, *newdefaultoptions=NULL;
|
||||
config_line_t *cl;
|
||||
int retval, i;
|
||||
int retval;
|
||||
setopt_err_t err = SETOPT_ERR_MISC;
|
||||
tor_assert(msg);
|
||||
|
||||
@ -4836,7 +4836,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
newoptions->command = command;
|
||||
newoptions->command_arg = command_arg ? tor_strdup(command_arg) : NULL;
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const char *body = i==0 ? cf_defaults : cf;
|
||||
if (!body)
|
||||
continue;
|
||||
@ -4880,8 +4880,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
* let's clean it up. -NM */
|
||||
|
||||
/* Change defaults. */
|
||||
int i;
|
||||
for (i = 0; testing_tor_network_defaults[i].name; ++i) {
|
||||
for (int i = 0; testing_tor_network_defaults[i].name; ++i) {
|
||||
const config_var_t *new_var = &testing_tor_network_defaults[i];
|
||||
config_var_t *old_var =
|
||||
config_find_option_mutable(&options_format, new_var->name);
|
||||
@ -4901,7 +4900,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
|
||||
newoptions->command_arg = command_arg ? tor_strdup(command_arg) : NULL;
|
||||
|
||||
/* Assign all options a second time. */
|
||||
for (i = 0; i < 2; ++i) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const char *body = i==0 ? cf_defaults : cf;
|
||||
if (!body)
|
||||
continue;
|
||||
@ -5917,10 +5916,10 @@ parse_dir_fallback_line(const char *line,
|
||||
ipv6_addrport_ptr = &ipv6_addrport;
|
||||
}
|
||||
} else if (!strcmpstart(cp, "weight=")) {
|
||||
int ok;
|
||||
int num_ok;
|
||||
const char *wstring = cp + strlen("weight=");
|
||||
weight = tor_parse_double(wstring, 0, (double)UINT64_MAX, &ok, NULL);
|
||||
if (!ok) {
|
||||
weight = tor_parse_double(wstring, 0, (double)UINT64_MAX, &num_ok, NULL);
|
||||
if (!num_ok) {
|
||||
log_warn(LD_CONFIG, "Invalid weight '%s' on FallbackDir line.", cp);
|
||||
weight=1.0;
|
||||
}
|
||||
@ -7410,8 +7409,8 @@ getinfo_helper_config(control_connection_t *conn,
|
||||
smartlist_free(sl);
|
||||
} else if (!strcmp(question, "config/defaults")) {
|
||||
smartlist_t *sl = smartlist_new();
|
||||
int i, dirauth_lines_seen = 0, fallback_lines_seen = 0;
|
||||
for (i = 0; option_vars_[i].name; ++i) {
|
||||
int dirauth_lines_seen = 0, fallback_lines_seen = 0;
|
||||
for (int i = 0; option_vars_[i].name; ++i) {
|
||||
const config_var_t *var = &option_vars_[i];
|
||||
if (var->initvalue != NULL) {
|
||||
if (strcmp(option_vars_[i].name, "DirAuthority") == 0) {
|
||||
@ -7439,14 +7438,13 @@ getinfo_helper_config(control_connection_t *conn,
|
||||
* We didn't see any directory authorities with default values,
|
||||
* so add the list of default authorities manually.
|
||||
*/
|
||||
const char **i;
|
||||
|
||||
/*
|
||||
* default_authorities is defined earlier in this file and
|
||||
* is a const char ** NULL-terminated array of dirauth config
|
||||
* lines.
|
||||
*/
|
||||
for (i = default_authorities; *i != NULL; ++i) {
|
||||
for (const char **i = default_authorities; *i != NULL; ++i) {
|
||||
char *val = esc_for_log(*i);
|
||||
smartlist_add_asprintf(sl, "DirAuthority %s\n", val);
|
||||
tor_free(val);
|
||||
|
@ -52,13 +52,13 @@ void connection_mark_for_close_internal_(connection_t *conn,
|
||||
* For all other cases, use connection_mark_and_flush() instead, which
|
||||
* checks for or_connection_t properly, instead. See below.
|
||||
*/
|
||||
#define connection_mark_and_flush_internal_(c,line,file) \
|
||||
do { \
|
||||
connection_t *tmp_conn_ = (c); \
|
||||
connection_mark_for_close_internal_(tmp_conn_, (line), (file)); \
|
||||
tmp_conn_->hold_open_until_flushed = 1; \
|
||||
IF_HAS_BUFFEREVENT(tmp_conn_, \
|
||||
connection_start_writing(tmp_conn_)); \
|
||||
#define connection_mark_and_flush_internal_(c,line,file) \
|
||||
do { \
|
||||
connection_t *tmp_conn__ = (c); \
|
||||
connection_mark_for_close_internal_(tmp_conn__, (line), (file)); \
|
||||
tmp_conn__->hold_open_until_flushed = 1; \
|
||||
IF_HAS_BUFFEREVENT(tmp_conn__, \
|
||||
connection_start_writing(tmp_conn__)); \
|
||||
} while (0)
|
||||
|
||||
#define connection_mark_and_flush_internal(c) \
|
||||
|
@ -2881,7 +2881,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
|
||||
or_circuit_t *or_circ = NULL;
|
||||
const or_options_t *options = get_options();
|
||||
begin_cell_t bcell;
|
||||
int r;
|
||||
int rv;
|
||||
uint8_t end_reason=0;
|
||||
|
||||
assert_circuit_ok(circ);
|
||||
@ -2906,10 +2906,10 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = begin_cell_parse(cell, &bcell, &end_reason);
|
||||
if (r < -1) {
|
||||
rv = begin_cell_parse(cell, &bcell, &end_reason);
|
||||
if (rv < -1) {
|
||||
return -END_CIRC_REASON_TORPROTOCOL;
|
||||
} else if (r == -1) {
|
||||
} else if (rv == -1) {
|
||||
tor_free(bcell.address);
|
||||
relay_send_end_cell_from_edge(rh.stream_id, circ, end_reason, NULL);
|
||||
return 0;
|
||||
|
@ -2275,14 +2275,13 @@ connection_or_send_certs_cell(or_connection_t *conn)
|
||||
var_cell_t *cell;
|
||||
size_t cell_len;
|
||||
ssize_t pos;
|
||||
int server_mode;
|
||||
|
||||
tor_assert(conn->base_.state == OR_CONN_STATE_OR_HANDSHAKING_V3);
|
||||
|
||||
if (! conn->handshake_state)
|
||||
return -1;
|
||||
server_mode = ! conn->handshake_state->started_here;
|
||||
if (tor_tls_get_my_certs(server_mode, &link_cert, &id_cert) < 0)
|
||||
const int conn_in_server_mode = ! conn->handshake_state->started_here;
|
||||
if (tor_tls_get_my_certs(conn_in_server_mode, &link_cert, &id_cert) < 0)
|
||||
return -1;
|
||||
tor_x509_cert_get_der(link_cert, &link_encoded, &link_len);
|
||||
tor_x509_cert_get_der(id_cert, &id_encoded, &id_len);
|
||||
@ -2295,7 +2294,7 @@ connection_or_send_certs_cell(or_connection_t *conn)
|
||||
cell->payload[0] = 2;
|
||||
pos = 1;
|
||||
|
||||
if (server_mode)
|
||||
if (conn_in_server_mode)
|
||||
cell->payload[pos] = OR_CERT_TYPE_TLS_LINK; /* Link cert */
|
||||
else
|
||||
cell->payload[pos] = OR_CERT_TYPE_AUTH_1024; /* client authentication */
|
||||
|
@ -594,7 +594,7 @@ typedef struct queued_event_s {
|
||||
|
||||
/** Pointer to int. If this is greater than 0, we don't allow new events to be
|
||||
* queued. */
|
||||
static tor_threadlocal_t block_event_queue;
|
||||
static tor_threadlocal_t block_event_queue_flag;
|
||||
|
||||
/** Holds a smartlist of queued_event_t objects that may need to be sent
|
||||
* to one or more controllers */
|
||||
@ -629,17 +629,17 @@ control_initialize_event_queue(void)
|
||||
|
||||
if (queued_control_events_lock == NULL) {
|
||||
queued_control_events_lock = tor_mutex_new();
|
||||
tor_threadlocal_init(&block_event_queue);
|
||||
tor_threadlocal_init(&block_event_queue_flag);
|
||||
}
|
||||
}
|
||||
|
||||
static int *
|
||||
get_block_event_queue(void)
|
||||
{
|
||||
int *val = tor_threadlocal_get(&block_event_queue);
|
||||
int *val = tor_threadlocal_get(&block_event_queue_flag);
|
||||
if (PREDICT_UNLIKELY(val == NULL)) {
|
||||
val = tor_malloc_zero(sizeof(int));
|
||||
tor_threadlocal_set(&block_event_queue, val);
|
||||
tor_threadlocal_set(&block_event_queue_flag, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
@ -1370,7 +1370,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
|
||||
goto err;
|
||||
}
|
||||
bad_password = 1;
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
sl = NULL;
|
||||
} else {
|
||||
@ -1382,7 +1382,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
|
||||
received, DIGEST_LEN))
|
||||
goto ok;
|
||||
});
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
sl = NULL;
|
||||
|
||||
@ -1410,7 +1410,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
|
||||
connection_printf_to_buf(conn, "515 Authentication failed: %s\r\n", errstr);
|
||||
connection_mark_for_close(TO_CONN(conn));
|
||||
if (sl) { /* clean up */
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
return 0;
|
||||
@ -1421,7 +1421,7 @@ handle_control_authenticate(control_connection_t *conn, uint32_t len,
|
||||
conn->base_.state = CONTROL_CONN_STATE_OPEN;
|
||||
tor_free(password);
|
||||
if (sl) { /* clean up */
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
return 0;
|
||||
@ -1850,11 +1850,10 @@ getinfo_helper_dir(control_connection_t *control_conn,
|
||||
const char *question, char **answer,
|
||||
const char **errmsg)
|
||||
{
|
||||
const node_t *node;
|
||||
const routerinfo_t *ri = NULL;
|
||||
(void) control_conn;
|
||||
if (!strcmpstart(question, "desc/id/")) {
|
||||
node = node_get_by_hex_id(question+strlen("desc/id/"));
|
||||
const routerinfo_t *ri = NULL;
|
||||
const node_t *node = node_get_by_hex_id(question+strlen("desc/id/"));
|
||||
if (node)
|
||||
ri = node->ri;
|
||||
if (ri) {
|
||||
@ -1863,9 +1862,10 @@ getinfo_helper_dir(control_connection_t *control_conn,
|
||||
*answer = tor_strndup(body, ri->cache_info.signed_descriptor_len);
|
||||
}
|
||||
} else if (!strcmpstart(question, "desc/name/")) {
|
||||
const routerinfo_t *ri = NULL;
|
||||
/* XXX Setting 'warn_if_unnamed' here is a bit silly -- the
|
||||
* warning goes to the user, not to the controller. */
|
||||
node = node_get_by_nickname(question+strlen("desc/name/"), 1);
|
||||
const node_t *node = node_get_by_nickname(question+strlen("desc/name/"), 1);
|
||||
if (node)
|
||||
ri = node->ri;
|
||||
if (ri) {
|
||||
@ -1959,7 +1959,9 @@ getinfo_helper_dir(control_connection_t *control_conn,
|
||||
*answer = tor_strndup(md->body, md->bodylen);
|
||||
}
|
||||
} else if (!strcmpstart(question, "desc-annotations/id/")) {
|
||||
node = node_get_by_hex_id(question+strlen("desc-annotations/id/"));
|
||||
const routerinfo_t *ri = NULL;
|
||||
const node_t *node =
|
||||
node_get_by_hex_id(question+strlen("desc-annotations/id/"));
|
||||
if (node)
|
||||
ri = node->ri;
|
||||
if (ri) {
|
||||
@ -4637,7 +4639,7 @@ add_onion_helper_clientauth(const char *arg, int *created, char **err_msg)
|
||||
|
||||
ok = 1;
|
||||
err:
|
||||
SMARTLIST_FOREACH(auth_args, char *, arg, tor_free(arg));
|
||||
SMARTLIST_FOREACH(auth_args, char *, item, tor_free(item));
|
||||
smartlist_free(auth_args);
|
||||
if (!ok) {
|
||||
rend_authorized_client_free(client);
|
||||
|
@ -2422,15 +2422,15 @@ networkstatus_get_detached_signatures(smartlist_t *consensuses)
|
||||
|
||||
/* Now get all the sigs for non-FLAV_NS consensuses */
|
||||
SMARTLIST_FOREACH_BEGIN(consensuses, networkstatus_t *, ns) {
|
||||
char *sigs;
|
||||
char *sigs_on_this_consensus;
|
||||
if (ns->flavor == FLAV_NS)
|
||||
continue;
|
||||
sigs = networkstatus_format_signatures(ns, 1);
|
||||
if (!sigs) {
|
||||
sigs_on_this_consensus = networkstatus_format_signatures(ns, 1);
|
||||
if (!sigs_on_this_consensus) {
|
||||
log_warn(LD_DIR, "Couldn't format signatures");
|
||||
goto err;
|
||||
}
|
||||
smartlist_add(elements, sigs);
|
||||
smartlist_add(elements, sigs_on_this_consensus);
|
||||
} SMARTLIST_FOREACH_END(ns);
|
||||
|
||||
/* Now add the FLAV_NS consensus signatrures. */
|
||||
@ -3101,12 +3101,12 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
|
||||
|
||||
/* Write the votes in <b>pending_vote_list</b> to disk. */
|
||||
static void
|
||||
write_v3_votes_to_disk(const smartlist_t *pending_vote_list)
|
||||
write_v3_votes_to_disk(const smartlist_t *pending_votes)
|
||||
{
|
||||
smartlist_t *votestrings = smartlist_new();
|
||||
char *votefile = NULL;
|
||||
|
||||
SMARTLIST_FOREACH(pending_vote_list, pending_vote_t *, v,
|
||||
SMARTLIST_FOREACH(pending_votes, pending_vote_t *, v,
|
||||
{
|
||||
sized_chunk_t *c = tor_malloc(sizeof(sized_chunk_t));
|
||||
c->bytes = v->vote_body->dir;
|
||||
|
@ -1455,7 +1455,6 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
|
||||
}
|
||||
} else {
|
||||
if (state_version) {
|
||||
time_t now = time(NULL);
|
||||
e->chosen_on_date = crypto_rand_time_range(now - 3600*24*30, now);
|
||||
e->chosen_by_version = tor_strdup(state_version);
|
||||
}
|
||||
|
@ -824,7 +824,6 @@ geoip_get_transport_history(void)
|
||||
static const char* no_transport_str = "<OR>";
|
||||
|
||||
clientmap_entry_t **ent;
|
||||
const char *transport_name = NULL;
|
||||
smartlist_t *string_chunks = smartlist_new();
|
||||
char *the_string = NULL;
|
||||
|
||||
@ -850,7 +849,7 @@ geoip_get_transport_history(void)
|
||||
HT_FOREACH(ent, clientmap, &client_history) {
|
||||
uintptr_t val;
|
||||
void *ptr;
|
||||
transport_name = (*ent)->transport_name;
|
||||
const char *transport_name = (*ent)->transport_name;
|
||||
if (!transport_name)
|
||||
transport_name = no_transport_str;
|
||||
|
||||
@ -916,13 +915,13 @@ geoip_get_dirreq_history(dirreq_type_t type)
|
||||
smartlist_t *dirreq_completed = NULL;
|
||||
uint32_t complete = 0, timeouts = 0, running = 0;
|
||||
int bufsize = 1024, written;
|
||||
dirreq_map_entry_t **ptr, **next, *ent;
|
||||
dirreq_map_entry_t **ptr, **next;
|
||||
struct timeval now;
|
||||
|
||||
tor_gettimeofday(&now);
|
||||
dirreq_completed = smartlist_new();
|
||||
for (ptr = HT_START(dirreqmap, &dirreq_map); ptr; ptr = next) {
|
||||
ent = *ptr;
|
||||
dirreq_map_entry_t *ent = *ptr;
|
||||
if (ent->type != type) {
|
||||
next = HT_NEXT(dirreqmap, &dirreq_map, ptr);
|
||||
continue;
|
||||
@ -1024,7 +1023,7 @@ geoip_get_client_history(geoip_client_action_t action,
|
||||
smartlist_t *entries = NULL;
|
||||
int n_countries = geoip_get_n_countries();
|
||||
int i;
|
||||
clientmap_entry_t **ent;
|
||||
clientmap_entry_t **cm_ent;
|
||||
unsigned *counts = NULL;
|
||||
unsigned total = 0;
|
||||
unsigned ipv4_count = 0, ipv6_count = 0;
|
||||
@ -1033,17 +1032,17 @@ geoip_get_client_history(geoip_client_action_t action,
|
||||
return -1;
|
||||
|
||||
counts = tor_calloc(n_countries, sizeof(unsigned));
|
||||
HT_FOREACH(ent, clientmap, &client_history) {
|
||||
HT_FOREACH(cm_ent, clientmap, &client_history) {
|
||||
int country;
|
||||
if ((*ent)->action != (int)action)
|
||||
if ((*cm_ent)->action != (int)action)
|
||||
continue;
|
||||
country = geoip_get_country_by_addr(&(*ent)->addr);
|
||||
country = geoip_get_country_by_addr(&(*cm_ent)->addr);
|
||||
if (country < 0)
|
||||
country = 0; /** unresolved requests are stored at index 0. */
|
||||
tor_assert(0 <= country && country < n_countries);
|
||||
++counts[country];
|
||||
++total;
|
||||
switch (tor_addr_family(&(*ent)->addr)) {
|
||||
switch (tor_addr_family(&(*cm_ent)->addr)) {
|
||||
case AF_INET:
|
||||
ipv4_count++;
|
||||
break;
|
||||
|
@ -542,13 +542,15 @@ node_get_by_hex_id(const char *hex_id)
|
||||
MOCK_IMPL(const node_t *,
|
||||
node_get_by_nickname,(const char *nickname, int warn_if_unnamed))
|
||||
{
|
||||
const node_t *node;
|
||||
if (!the_nodelist)
|
||||
return NULL;
|
||||
|
||||
/* Handle these cases: DIGEST, $DIGEST, $DIGEST=name, $DIGEST~name. */
|
||||
if ((node = node_get_by_hex_id(nickname)) != NULL)
|
||||
{
|
||||
const node_t *node;
|
||||
if ((node = node_get_by_hex_id(nickname)) != NULL)
|
||||
return node;
|
||||
}
|
||||
|
||||
if (!strcasecmp(nickname, UNNAMED_ROUTER_NICKNAME))
|
||||
return NULL;
|
||||
|
@ -2701,7 +2701,6 @@ rend_service_intro_has_opened(origin_circuit_t *circuit)
|
||||
char auth[DIGEST_LEN + 9];
|
||||
char serviceid[REND_SERVICE_ID_LEN_BASE32+1];
|
||||
int reason = END_CIRC_REASON_TORPROTOCOL;
|
||||
crypto_pk_t *intro_key;
|
||||
|
||||
tor_assert(circuit->base_.purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO);
|
||||
#ifndef NON_ANONYMOUS_MODE_ENABLED
|
||||
@ -2775,7 +2774,7 @@ rend_service_intro_has_opened(origin_circuit_t *circuit)
|
||||
(unsigned)circuit->base_.n_circ_id, serviceid);
|
||||
|
||||
/* Use the intro key instead of the service key in ESTABLISH_INTRO. */
|
||||
intro_key = circuit->intro_key;
|
||||
crypto_pk_t *intro_key = circuit->intro_key;
|
||||
/* Build the payload for a RELAY_ESTABLISH_INTRO cell. */
|
||||
r = crypto_pk_asn1_encode(intro_key, buf+2,
|
||||
RELAY_PAYLOAD_SIZE-2);
|
||||
|
@ -2948,22 +2948,22 @@ static hs_stats_t *hs_stats = NULL;
|
||||
static hs_stats_t *
|
||||
hs_stats_new(void)
|
||||
{
|
||||
hs_stats_t * hs_stats = tor_malloc_zero(sizeof(hs_stats_t));
|
||||
hs_stats->onions_seen_this_period = digestmap_new();
|
||||
hs_stats_t *new_hs_stats = tor_malloc_zero(sizeof(hs_stats_t));
|
||||
new_hs_stats->onions_seen_this_period = digestmap_new();
|
||||
|
||||
return hs_stats;
|
||||
return new_hs_stats;
|
||||
}
|
||||
|
||||
/** Free an hs_stats_t structure. */
|
||||
static void
|
||||
hs_stats_free(hs_stats_t *hs_stats)
|
||||
hs_stats_free(hs_stats_t *victim_hs_stats)
|
||||
{
|
||||
if (!hs_stats) {
|
||||
if (!victim_hs_stats) {
|
||||
return;
|
||||
}
|
||||
|
||||
digestmap_free(hs_stats->onions_seen_this_period, NULL);
|
||||
tor_free(hs_stats);
|
||||
digestmap_free(victim_hs_stats->onions_seen_this_period, NULL);
|
||||
tor_free(victim_hs_stats);
|
||||
}
|
||||
|
||||
/** Initialize hidden service statistics. */
|
||||
|
@ -3079,17 +3079,17 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
|
||||
}
|
||||
|
||||
if (emit_ed_sigs) {
|
||||
char digest[DIGEST256_LEN];
|
||||
char sha256_digest[DIGEST256_LEN];
|
||||
smartlist_add(chunks, tor_strdup("router-sig-ed25519 "));
|
||||
crypto_digest_smartlist_prefix(digest, DIGEST256_LEN,
|
||||
crypto_digest_smartlist_prefix(sha256_digest, DIGEST256_LEN,
|
||||
ED_DESC_SIGNATURE_PREFIX,
|
||||
chunks, "", DIGEST_SHA256);
|
||||
ed25519_signature_t sig;
|
||||
ed25519_signature_t ed_sig;
|
||||
char buf[ED25519_SIG_BASE64_LEN+1];
|
||||
if (ed25519_sign(&sig, (const uint8_t*)digest, DIGEST256_LEN,
|
||||
if (ed25519_sign(&ed_sig, (const uint8_t*)sha256_digest, DIGEST256_LEN,
|
||||
signing_keypair) < 0)
|
||||
goto err;
|
||||
if (ed25519_signature_to_base64(buf, &sig) < 0)
|
||||
if (ed25519_signature_to_base64(buf, &ed_sig) < 0)
|
||||
goto err;
|
||||
|
||||
smartlist_add_asprintf(chunks, "%s\n", buf);
|
||||
@ -3163,7 +3163,7 @@ extrainfo_dump_to_string(char **s_out, extrainfo_t *extrainfo,
|
||||
|
||||
done:
|
||||
tor_free(s);
|
||||
SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(chunks, char *, chunk, tor_free(chunk));
|
||||
smartlist_free(chunks);
|
||||
tor_free(s_dup);
|
||||
tor_free(ed_cert_line);
|
||||
|
@ -121,14 +121,14 @@ read_encrypted_secret_key(ed25519_secret_key_t *out,
|
||||
saved_errno = EINVAL;
|
||||
goto done;
|
||||
}
|
||||
const int r = crypto_unpwbox(&secret, &secret_len,
|
||||
encrypted_key, encrypted_len,
|
||||
pwbuf, pwlen);
|
||||
if (r == UNPWBOX_CORRUPTED) {
|
||||
const int r_unbox = crypto_unpwbox(&secret, &secret_len,
|
||||
encrypted_key, encrypted_len,
|
||||
pwbuf, pwlen);
|
||||
if (r_unbox == UNPWBOX_CORRUPTED) {
|
||||
log_err(LD_OR, "%s is corrupted.", fname);
|
||||
saved_errno = EINVAL;
|
||||
goto done;
|
||||
} else if (r == UNPWBOX_OKAY) {
|
||||
} else if (r_unbox == UNPWBOX_OKAY) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -917,7 +917,6 @@ authority_certs_fetch_missing(networkstatus_t *status, time_t now,
|
||||
*/
|
||||
digestmap_t *pending_id;
|
||||
fp_pair_map_t *pending_cert;
|
||||
authority_cert_t *cert;
|
||||
/*
|
||||
* The missing_id_digests smartlist will hold a list of id digests
|
||||
* we want to fetch the newest cert for; the missing_cert_digests
|
||||
@ -1027,8 +1026,9 @@ authority_certs_fetch_missing(networkstatus_t *status, time_t now,
|
||||
}
|
||||
|
||||
SMARTLIST_FOREACH_BEGIN(voter->sigs, document_signature_t *, sig) {
|
||||
cert = authority_cert_get_by_digests(voter->identity_digest,
|
||||
sig->signing_key_digest);
|
||||
authority_cert_t *cert =
|
||||
authority_cert_get_by_digests(voter->identity_digest,
|
||||
sig->signing_key_digest);
|
||||
if (cert) {
|
||||
if (now < cert->expires)
|
||||
download_status_reset_by_sk_in_cl(cl, sig->signing_key_digest);
|
||||
|
@ -1779,11 +1779,11 @@ router_parse_entry_from_string(const char *s, const char *end,
|
||||
if (cache_copy) {
|
||||
size_t len = router->cache_info.signed_descriptor_len +
|
||||
router->cache_info.annotations_len;
|
||||
char *cp =
|
||||
char *signed_body =
|
||||
router->cache_info.signed_descriptor_body = tor_malloc(len+1);
|
||||
if (prepend_annotations) {
|
||||
memcpy(cp, prepend_annotations, prepend_len);
|
||||
cp += prepend_len;
|
||||
memcpy(signed_body, prepend_annotations, prepend_len);
|
||||
signed_body += prepend_len;
|
||||
}
|
||||
/* This assertion will always succeed.
|
||||
* len == signed_desc_len + annotations_len
|
||||
@ -1791,9 +1791,9 @@ router_parse_entry_from_string(const char *s, const char *end,
|
||||
* == end-start_of_annotations + prepend_len
|
||||
* We already wrote prepend_len bytes into the buffer; now we're
|
||||
* writing end-start_of_annotations -NM. */
|
||||
tor_assert(cp+(end-start_of_annotations) ==
|
||||
tor_assert(signed_body+(end-start_of_annotations) ==
|
||||
router->cache_info.signed_descriptor_body+len);
|
||||
memcpy(cp, start_of_annotations, end-start_of_annotations);
|
||||
memcpy(signed_body, start_of_annotations, end-start_of_annotations);
|
||||
router->cache_info.signed_descriptor_body[len] = '\0';
|
||||
tor_assert(strlen(router->cache_info.signed_descriptor_body) == len);
|
||||
}
|
||||
@ -3546,7 +3546,6 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
common_digests_t ns_digests;
|
||||
const char *cert, *end_of_header, *end_of_footer, *s_dup = s;
|
||||
directory_token_t *tok;
|
||||
int ok;
|
||||
struct in_addr in;
|
||||
int i, inorder, n_signatures = 0;
|
||||
memarea_t *area = NULL, *rs_area = NULL;
|
||||
@ -3636,9 +3635,10 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
} else {
|
||||
tok = find_opt_by_keyword(tokens, K_CONSENSUS_METHOD);
|
||||
if (tok) {
|
||||
int num_ok;
|
||||
ns->consensus_method = (int)tor_parse_long(tok->args[0], 10, 1, INT_MAX,
|
||||
&ok, NULL);
|
||||
if (!ok)
|
||||
&num_ok, NULL);
|
||||
if (!num_ok)
|
||||
goto err;
|
||||
} else {
|
||||
ns->consensus_method = 1;
|
||||
@ -3659,14 +3659,17 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
|
||||
tok = find_by_keyword(tokens, K_VOTING_DELAY);
|
||||
tor_assert(tok->n_args >= 2);
|
||||
ns->vote_seconds =
|
||||
(int) tor_parse_long(tok->args[0], 10, 0, INT_MAX, &ok, NULL);
|
||||
if (!ok)
|
||||
goto err;
|
||||
ns->dist_seconds =
|
||||
(int) tor_parse_long(tok->args[1], 10, 0, INT_MAX, &ok, NULL);
|
||||
if (!ok)
|
||||
goto err;
|
||||
{
|
||||
int ok;
|
||||
ns->vote_seconds =
|
||||
(int) tor_parse_long(tok->args[0], 10, 0, INT_MAX, &ok, NULL);
|
||||
if (!ok)
|
||||
goto err;
|
||||
ns->dist_seconds =
|
||||
(int) tor_parse_long(tok->args[1], 10, 0, INT_MAX, &ok, NULL);
|
||||
if (!ok)
|
||||
goto err;
|
||||
}
|
||||
if (ns->valid_after +
|
||||
(get_options()->TestingTorNetwork ?
|
||||
MIN_VOTE_INTERVAL_TESTING : MIN_VOTE_INTERVAL) > ns->fresh_until) {
|
||||
@ -3817,6 +3820,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
goto err;
|
||||
}
|
||||
voter->addr = ntohl(in.s_addr);
|
||||
int ok;
|
||||
voter->dir_port = (uint16_t)
|
||||
tor_parse_long(tok->args[4], 10, 0, 65535, &ok, NULL);
|
||||
if (!ok)
|
||||
@ -3864,8 +3868,8 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
|
||||
(tok = find_opt_by_keyword(tokens, K_LEGACY_DIR_KEY))) {
|
||||
int bad = 1;
|
||||
if (strlen(tok->args[0]) == HEX_DIGEST_LEN) {
|
||||
networkstatus_voter_info_t *voter = smartlist_get(ns->voters, 0);
|
||||
if (base16_decode(voter->legacy_id_digest, DIGEST_LEN,
|
||||
networkstatus_voter_info_t *voter_0 = smartlist_get(ns->voters, 0);
|
||||
if (base16_decode(voter_0->legacy_id_digest, DIGEST_LEN,
|
||||
tok->args[0], HEX_DIGEST_LEN) != DIGEST_LEN)
|
||||
bad = 1;
|
||||
else
|
||||
|
@ -496,13 +496,13 @@ scheduler_run, (void))
|
||||
|
||||
/* Readd any channels we need to */
|
||||
if (to_readd) {
|
||||
SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, chan) {
|
||||
chan->scheduler_state = SCHED_CHAN_PENDING;
|
||||
SMARTLIST_FOREACH_BEGIN(to_readd, channel_t *, readd_chan) {
|
||||
readd_chan->scheduler_state = SCHED_CHAN_PENDING;
|
||||
smartlist_pqueue_add(channels_pending,
|
||||
scheduler_compare_channels,
|
||||
STRUCT_OFFSET(channel_t, sched_heap_idx),
|
||||
chan);
|
||||
} SMARTLIST_FOREACH_END(chan);
|
||||
readd_chan);
|
||||
} SMARTLIST_FOREACH_END(readd_chan);
|
||||
smartlist_free(to_readd);
|
||||
}
|
||||
|
||||
|
@ -1425,7 +1425,7 @@ create_managed_proxy_environment(const managed_proxy_t *mp)
|
||||
*
|
||||
* Requires that proxy_argv have at least one element. */
|
||||
STATIC managed_proxy_t *
|
||||
managed_proxy_create(const smartlist_t *transport_list,
|
||||
managed_proxy_create(const smartlist_t *with_transport_list,
|
||||
char **proxy_argv, int is_server)
|
||||
{
|
||||
managed_proxy_t *mp = tor_malloc_zero(sizeof(managed_proxy_t));
|
||||
@ -1436,7 +1436,7 @@ managed_proxy_create(const smartlist_t *transport_list,
|
||||
mp->proxy_uri = get_pt_proxy_uri();
|
||||
|
||||
mp->transports_to_launch = smartlist_new();
|
||||
SMARTLIST_FOREACH(transport_list, const char *, transport,
|
||||
SMARTLIST_FOREACH(with_transport_list, const char *, transport,
|
||||
add_transport_to_proxy(transport, mp));
|
||||
|
||||
/* register the managed proxy */
|
||||
@ -1460,7 +1460,7 @@ managed_proxy_create(const smartlist_t *transport_list,
|
||||
* elements, containing at least one element.
|
||||
**/
|
||||
MOCK_IMPL(void,
|
||||
pt_kickstart_proxy, (const smartlist_t *transport_list,
|
||||
pt_kickstart_proxy, (const smartlist_t *with_transport_list,
|
||||
char **proxy_argv, int is_server))
|
||||
{
|
||||
managed_proxy_t *mp=NULL;
|
||||
@ -1473,7 +1473,7 @@ pt_kickstart_proxy, (const smartlist_t *transport_list,
|
||||
mp = get_managed_proxy_by_argv_and_type(proxy_argv, is_server);
|
||||
|
||||
if (!mp) { /* we haven't seen this proxy before */
|
||||
managed_proxy_create(transport_list, proxy_argv, is_server);
|
||||
managed_proxy_create(with_transport_list, proxy_argv, is_server);
|
||||
|
||||
} else { /* known proxy. add its transport to its transport list */
|
||||
if (mp->was_around_before_config_read) {
|
||||
@ -1490,14 +1490,14 @@ pt_kickstart_proxy, (const smartlist_t *transport_list,
|
||||
/* For each new transport, check if the managed proxy used to
|
||||
support it before the SIGHUP. If that was the case, make sure
|
||||
it doesn't get removed because we might reuse it. */
|
||||
SMARTLIST_FOREACH_BEGIN(transport_list, const char *, transport) {
|
||||
SMARTLIST_FOREACH_BEGIN(with_transport_list, const char *, transport) {
|
||||
old_transport = transport_get_by_name(transport);
|
||||
if (old_transport)
|
||||
old_transport->marked_for_removal = 0;
|
||||
} SMARTLIST_FOREACH_END(transport);
|
||||
}
|
||||
|
||||
SMARTLIST_FOREACH(transport_list, const char *, transport,
|
||||
SMARTLIST_FOREACH(with_transport_list, const char *, transport,
|
||||
add_transport_to_proxy(transport, mp));
|
||||
free_execve_args(proxy_argv);
|
||||
}
|
||||
|
@ -662,7 +662,6 @@ main(int argc, const char **argv)
|
||||
{
|
||||
int i;
|
||||
int list=0, n_enabled=0;
|
||||
benchmark_t *b;
|
||||
char *errmsg;
|
||||
or_options_t *options;
|
||||
|
||||
@ -672,10 +671,10 @@ main(int argc, const char **argv)
|
||||
if (!strcmp(argv[i], "--list")) {
|
||||
list = 1;
|
||||
} else {
|
||||
benchmark_t *b = find_benchmark(argv[i]);
|
||||
benchmark_t *benchmark = find_benchmark(argv[i]);
|
||||
++n_enabled;
|
||||
if (b) {
|
||||
b->enabled = 1;
|
||||
if (benchmark) {
|
||||
benchmark->enabled = 1;
|
||||
} else {
|
||||
printf("No such benchmark as %s\n", argv[i]);
|
||||
}
|
||||
@ -700,7 +699,7 @@ main(int argc, const char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (b = benchmarks; b->name; ++b) {
|
||||
for (benchmark_t *b = benchmarks; b->name; ++b) {
|
||||
if (b->enabled || n_enabled == 0) {
|
||||
printf("===== %s =====\n", b->name);
|
||||
if (!list)
|
||||
|
@ -83,12 +83,12 @@ test_addr_basic(void *arg)
|
||||
tt_assert_test_fmt_type(a,b,e1" "#op" "e2,struct in6_addr*, \
|
||||
(memcmp(val1_->s6_addr, val2_->s6_addr, 16) op 0), \
|
||||
char *, "%s", \
|
||||
{ int i; char *cp; \
|
||||
{ char *cp; \
|
||||
cp = print_ = tor_malloc(64); \
|
||||
for (i=0;i<16;++i) { \
|
||||
for (int ii_=0;i<16;++i) { \
|
||||
tor_snprintf(cp, 3,"%02x", (unsigned)value_->s6_addr[i]);\
|
||||
cp += 2; \
|
||||
if (i != 15) *cp++ = ':'; \
|
||||
if (ii_ != 15) *cp++ = ':'; \
|
||||
} \
|
||||
}, \
|
||||
{ tor_free(print_); }, \
|
||||
|
@ -178,10 +178,10 @@ test_buffers_basic(void *arg)
|
||||
|
||||
/* Try adding a string too long for any freelist. */
|
||||
{
|
||||
char *cp = tor_malloc_zero(65536);
|
||||
char *mem = tor_malloc_zero(65536);
|
||||
buf = buf_new();
|
||||
write_to_buf(cp, 65536, buf);
|
||||
tor_free(cp);
|
||||
write_to_buf(mem, 65536, buf);
|
||||
tor_free(mem);
|
||||
|
||||
tt_int_op(buf_datalen(buf), OP_EQ, 65536);
|
||||
buf_free(buf);
|
||||
|
@ -882,8 +882,8 @@ test_cfmt_resolved_cells(void *arg)
|
||||
memset(&rh, 0, sizeof(rh)); \
|
||||
} while (0)
|
||||
#define CLEAR_ADDRS() do { \
|
||||
SMARTLIST_FOREACH(addrs, address_ttl_t *, a, \
|
||||
address_ttl_free(a); ); \
|
||||
SMARTLIST_FOREACH(addrs, address_ttl_t *, aa_, \
|
||||
address_ttl_free(aa_); ); \
|
||||
smartlist_clear(addrs); \
|
||||
} while (0)
|
||||
#define SET_CELL(s) do { \
|
||||
|
@ -132,7 +132,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_str_op("def",OP_EQ, smartlist_get(sl, 5));
|
||||
tt_str_op(" ",OP_EQ, smartlist_get(sl, 6));
|
||||
tt_str_op("ghijk",OP_EQ, smartlist_get(sl, 7));
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
smartlist_split_string(sl, "a,bbd,cdef", ",", SPLIT_SKIP_SPACE, 0);
|
||||
@ -149,7 +149,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_str_op("bnud",OP_EQ, smartlist_get(sl,6));
|
||||
tt_str_op("",OP_EQ, smartlist_get(sl,7));
|
||||
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
smartlist_split_string(sl, " ab\tc \td ef ", NULL,
|
||||
@ -165,7 +165,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_str_op("ghi",OP_EQ, smartlist_get(sl,4));
|
||||
tt_str_op("j",OP_EQ, smartlist_get(sl,5));
|
||||
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
cp_alloc = smartlist_join_strings(sl, "XY", 0, NULL);
|
||||
@ -186,7 +186,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_int_op(5,OP_EQ, smartlist_len(sl));
|
||||
tt_str_op("z",OP_EQ, smartlist_get(sl, 3));
|
||||
tt_str_op("zhasd <> <> bnud<>",OP_EQ, smartlist_get(sl, 4));
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
smartlist_split_string(sl, "abcd\n", "\n",
|
||||
@ -198,7 +198,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_int_op(2,OP_EQ, smartlist_len(sl));
|
||||
tt_str_op("efgh",OP_EQ, smartlist_get(sl, 1));
|
||||
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
/* Test swapping, shuffling, and sorting. */
|
||||
@ -286,7 +286,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_str_op(cp_alloc,OP_EQ, "and");
|
||||
tor_free(cp_alloc);
|
||||
tt_int_op(smartlist_len(sl),OP_EQ, 6);
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
cp_alloc = smartlist_pop_last(sl);
|
||||
tt_ptr_op(cp_alloc,OP_EQ, NULL);
|
||||
@ -326,7 +326,7 @@ test_container_smartlist_strings(void *arg)
|
||||
tt_assert(!allsame);
|
||||
tt_assert(allin);
|
||||
}
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_clear(sl);
|
||||
|
||||
/* Test string_remove and remove and join_strings2 */
|
||||
@ -348,7 +348,7 @@ test_container_smartlist_strings(void *arg)
|
||||
|
||||
done:
|
||||
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
tor_free(cp_alloc);
|
||||
}
|
||||
@ -437,7 +437,7 @@ test_container_smartlist_digests(void *arg)
|
||||
tt_mem_op(smartlist_get(sl, 1),OP_EQ, "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ test_container_smartlist_join(void *arg)
|
||||
smartlist_free(sl3);
|
||||
SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
|
||||
smartlist_free(sl2);
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
tor_free(joined);
|
||||
}
|
||||
@ -528,7 +528,7 @@ test_container_smartlist_pos(void *arg)
|
||||
tt_int_op(smartlist_pos(sl, smartlist_get(sl,6)), ==, 6);
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
|
||||
@ -1140,7 +1140,7 @@ test_container_smartlist_most_frequent(void *arg)
|
||||
tt_str_op(cp, ==, "def"); /* No tie */
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(sl, char *, str, tor_free(str));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
|
||||
|
@ -704,8 +704,8 @@ test_dir_parse_router_list(void *arg)
|
||||
"9a651ee03b64325959e8f1b46f2b689b30750b4c");
|
||||
|
||||
/* Now tidy up */
|
||||
SMARTLIST_FOREACH(dest, routerinfo_t *, ri, routerinfo_free(ri));
|
||||
SMARTLIST_FOREACH(invalid, uint8_t *, d, tor_free(d));
|
||||
SMARTLIST_FOREACH(dest, routerinfo_t *, rinfo, routerinfo_free(rinfo));
|
||||
SMARTLIST_FOREACH(invalid, uint8_t *, dig, tor_free(dig));
|
||||
smartlist_clear(dest);
|
||||
smartlist_clear(invalid);
|
||||
|
||||
@ -741,9 +741,9 @@ test_dir_parse_router_list(void *arg)
|
||||
else
|
||||
SMARTLIST_FOREACH(dest, extrainfo_t *, ei, extrainfo_free(ei));
|
||||
smartlist_free(dest);
|
||||
SMARTLIST_FOREACH(invalid, uint8_t *, d, tor_free(d));
|
||||
SMARTLIST_FOREACH(invalid, uint8_t *, dig, tor_free(dig));
|
||||
smartlist_free(invalid);
|
||||
SMARTLIST_FOREACH(chunks, char *, cp, tor_free(cp));
|
||||
SMARTLIST_FOREACH(chunks, char *, chunk, tor_free(chunk));
|
||||
smartlist_free(chunks);
|
||||
routerinfo_free(ri);
|
||||
if (map) {
|
||||
@ -1169,7 +1169,7 @@ test_dir_fp_pairs(void *arg)
|
||||
tt_mem_op(pair->second,OP_EQ, "Use AES-256 instead.", DIGEST_LEN);
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(sl, fp_pair_t *, pair, tor_free(pair));
|
||||
SMARTLIST_FOREACH(sl, fp_pair_t *, pair_to_free, tor_free(pair_to_free));
|
||||
smartlist_free(sl);
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ NS(test_main)(void *arg)
|
||||
static int resolve_retval = 0;
|
||||
static int resolve_made_conn_pending = 0;
|
||||
static char *resolved_name = NULL;
|
||||
static cached_resolve_t *cache_entry = NULL;
|
||||
static cached_resolve_t *cache_entry_mock = NULL;
|
||||
|
||||
static int n_fake_impl = 0;
|
||||
|
||||
@ -85,8 +85,8 @@ NS(dns_resolve_impl)(edge_connection_t *exitconn, int is_resolve,
|
||||
if (hostname_out && resolved_name)
|
||||
*hostname_out = tor_strdup(resolved_name);
|
||||
|
||||
if (resolve_out && cache_entry)
|
||||
*resolve_out = cache_entry;
|
||||
if (resolve_out && cache_entry_mock)
|
||||
*resolve_out = cache_entry_mock;
|
||||
|
||||
n_fake_impl++;
|
||||
|
||||
@ -213,7 +213,7 @@ NS(test_main)(void *arg)
|
||||
|
||||
exitconn->on_circuit = &(on_circuit->base_);
|
||||
|
||||
cache_entry = fake_resolved;
|
||||
cache_entry_mock = fake_resolved;
|
||||
|
||||
prev_n_send_resolved_cell_replacement =
|
||||
n_send_resolved_cell_replacement;
|
||||
|
@ -716,7 +716,7 @@ test_md_parse(void *arg)
|
||||
tt_int_op(md->ipv6_orport, OP_EQ, 9090);
|
||||
|
||||
done:
|
||||
SMARTLIST_FOREACH(mds, microdesc_t *, md, microdesc_free(md));
|
||||
SMARTLIST_FOREACH(mds, microdesc_t *, mdsc, microdesc_free(mdsc));
|
||||
smartlist_free(mds);
|
||||
SMARTLIST_FOREACH(invalid, char *, cp, tor_free(cp));
|
||||
smartlist_free(invalid);
|
||||
|
@ -523,18 +523,17 @@ test_policies_general(void *arg)
|
||||
|
||||
/* Test a too-long policy. */
|
||||
{
|
||||
int i;
|
||||
char *policy = NULL;
|
||||
char *policy_strng = NULL;
|
||||
smartlist_t *chunks = smartlist_new();
|
||||
smartlist_add(chunks, tor_strdup("accept "));
|
||||
for (i=1; i<10000; ++i)
|
||||
smartlist_add_asprintf(chunks, "%d,", i);
|
||||
smartlist_add(chunks, tor_strdup("20000"));
|
||||
policy = smartlist_join_strings(chunks, "", 0, NULL);
|
||||
policy_strng = smartlist_join_strings(chunks, "", 0, NULL);
|
||||
SMARTLIST_FOREACH(chunks, char *, ch, tor_free(ch));
|
||||
smartlist_free(chunks);
|
||||
short_parsed = parse_short_policy(policy);/* shouldn't be accepted */
|
||||
tor_free(policy);
|
||||
short_parsed = parse_short_policy(policy_strng);/* shouldn't be accepted */
|
||||
tor_free(policy_strng);
|
||||
tt_ptr_op(NULL, OP_EQ, short_parsed);
|
||||
}
|
||||
|
||||
|
@ -107,12 +107,12 @@ test_pt_parsing(void *arg)
|
||||
tt_assert(parse_smethod_line(line, mp) == 0);
|
||||
tt_int_op(1, OP_EQ, smartlist_len(mp->transports));
|
||||
{
|
||||
const transport_t *transport = smartlist_get(mp->transports, 0);
|
||||
tt_assert(transport);
|
||||
tt_str_op(transport->name, OP_EQ, "trebuchet");
|
||||
tt_int_op(transport->port, OP_EQ, 9999);
|
||||
tt_str_op(fmt_addr(&transport->addr), OP_EQ, "127.0.0.1");
|
||||
tt_str_op(transport->extra_info_args, OP_EQ,
|
||||
const transport_t *transport_ = smartlist_get(mp->transports, 0);
|
||||
tt_assert(transport_);
|
||||
tt_str_op(transport_->name, OP_EQ, "trebuchet");
|
||||
tt_int_op(transport_->port, OP_EQ, 9999);
|
||||
tt_str_op(fmt_addr(&transport_->addr), OP_EQ, "127.0.0.1");
|
||||
tt_str_op(transport_->extra_info_args, OP_EQ,
|
||||
"counterweight=3,sling=snappy");
|
||||
}
|
||||
reset_mp(mp);
|
||||
|
@ -139,7 +139,7 @@ channel_flush_some_cells_mock_free_all(void)
|
||||
static void
|
||||
channel_flush_some_cells_mock_set(channel_t *chan, ssize_t num_cells)
|
||||
{
|
||||
flush_mock_channel_t *flush_mock_ch = NULL;
|
||||
int found = 0;
|
||||
|
||||
if (!chan) return;
|
||||
if (num_cells <= 0) return;
|
||||
@ -155,6 +155,7 @@ channel_flush_some_cells_mock_set(channel_t *chan, ssize_t num_cells)
|
||||
if (flush_mock_ch->chan == chan) {
|
||||
/* Found it */
|
||||
flush_mock_ch->cells = num_cells;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@ -164,8 +165,9 @@ channel_flush_some_cells_mock_set(channel_t *chan, ssize_t num_cells)
|
||||
}
|
||||
} SMARTLIST_FOREACH_END(flush_mock_ch);
|
||||
|
||||
if (!flush_mock_ch) {
|
||||
if (! found) {
|
||||
/* The loop didn't find it */
|
||||
flush_mock_channel_t *flush_mock_ch;
|
||||
flush_mock_ch = tor_malloc_zero(sizeof(*flush_mock_ch));
|
||||
flush_mock_ch->chan = chan;
|
||||
flush_mock_ch->cells = num_cells;
|
||||
|
@ -2009,9 +2009,9 @@ test_util_strmisc(void *arg)
|
||||
/* Test hex_str */
|
||||
{
|
||||
char binary_data[68];
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(binary_data); ++i)
|
||||
binary_data[i] = i;
|
||||
size_t idx;
|
||||
for (idx = 0; idx < sizeof(binary_data); ++idx)
|
||||
binary_data[idx] = idx;
|
||||
tt_str_op(hex_str(binary_data, 0),OP_EQ, "");
|
||||
tt_str_op(hex_str(binary_data, 1),OP_EQ, "00");
|
||||
tt_str_op(hex_str(binary_data, 17),OP_EQ,
|
||||
|
Loading…
Reference in New Issue
Block a user