Commit e273890b authored by Nick Mathewson's avatar Nick Mathewson 👁
Browse files

Merge branch 'cov217_master'

parents 734e860d 0317dc2b
o Code simplification and refactoring:
- Use tor_sscanf in place of scanf in more places through the
code. This makes us a little more locale-independent, and
should help shut up code-analysis tools that can't tell
a safe sscanf string from a dangerous one.
......@@ -264,7 +264,7 @@ tor_decode_libevent_version(const char *v)
/* Try the new preferred "1.4.11-stable" format.
* Also accept "1.4.14b-stable". */
fields = sscanf(v, "%u.%u.%u%c%c", &major, &minor, &patchlevel, &c, &e);
fields = tor_sscanf(v, "%u.%u.%u%c%c", &major, &minor, &patchlevel, &c, &e);
if (fields == 3 ||
((fields == 4 || fields == 5 ) && (c == '-' || c == '_')) ||
(fields == 5 && TOR_ISALPHA(c) && (e == '-' || e == '_'))) {
......@@ -272,7 +272,7 @@ tor_decode_libevent_version(const char *v)
}
/* Try the old "1.3e" format. */
fields = sscanf(v, "%u.%u%c%c", &major, &minor, &c, &extra);
fields = tor_sscanf(v, "%u.%u%c%c", &major, &minor, &c, &extra);
if (fields == 3 && TOR_ISALPHA(c)) {
return V_OLD(major, minor, c);
} else if (fields == 2) {
......
......@@ -2367,7 +2367,7 @@ options_trial_assign(config_line_t *list, int use_defaults,
* Called from option_reset() and config_free(). */
static void
option_clear(const config_format_t *fmt, or_options_t *options,
const const config_var_t *var)
const config_var_t *var)
{
void *lvalue = STRUCT_VAR_P(options, var->var_offset);
(void)fmt; /* unused */
......
......@@ -2592,7 +2592,7 @@ client_likes_consensus(networkstatus_t *v, const char *want_url)
* Always return 0. */
static int
directory_handle_command_get(dir_connection_t *conn, const char *headers,
const char *body, size_t body_len)
const char *req_body, size_t req_body_len)
{
size_t dlen;
char *url, *url_mem, *header;
......@@ -2602,8 +2602,8 @@ directory_handle_command_get(dir_connection_t *conn, const char *headers,
size_t url_len;
/* We ignore the body of a GET request. */
(void)body;
(void)body_len;
(void)req_body;
(void)req_body_len;
log_debug(LD_DIRSERV,"Received GET command.");
......
......@@ -1831,8 +1831,8 @@ evdns_server_request_respond(struct evdns_server_request *_req, int err)
r = sendto(port->socket, req->response, req->response_len, 0,
(struct sockaddr*) &req->addr, req->addrlen);
if (r<0) {
int err = last_error(port->socket);
if (! error_is_eagain(err))
int error = last_error(port->socket);
if (! error_is_eagain(error))
return -1;
if (port->pending_replies) {
......
......@@ -116,10 +116,10 @@ geoip_parse_entry(const char *line)
++line;
if (*line == '#')
return 0;
if (sscanf(line,"%u,%u,%2s", &low, &high, b) == 3) {
if (tor_sscanf(line,"%u,%u,%2s", &low, &high, b) == 3) {
geoip_add_entry(low, high, b);
return 0;
} else if (sscanf(line,"\"%u\",\"%u\",\"%2s\",", &low, &high, b) == 3) {
} else if (tor_sscanf(line,"\"%u\",\"%u\",\"%2s\",", &low, &high, b) == 3) {
geoip_add_entry(low, high, b);
return 0;
} else {
......
......@@ -83,15 +83,15 @@ policy_expand_private(smartlist_t **policy)
continue;
}
for (i = 0; private_nets[i]; ++i) {
addr_policy_t policy;
memcpy(&policy, p, sizeof(addr_policy_t));
policy.is_private = 0;
policy.is_canonical = 0;
if (tor_addr_parse_mask_ports(private_nets[i], &policy.addr,
&policy.maskbits, &port_min, &port_max)<0) {
addr_policy_t newpolicy;
memcpy(&newpolicy, p, sizeof(addr_policy_t));
newpolicy.is_private = 0;
newpolicy.is_canonical = 0;
if (tor_addr_parse_mask_ports(private_nets[i], &newpolicy.addr,
&newpolicy.maskbits, &port_min, &port_max)<0) {
tor_assert(0);
}
smartlist_add(tmp, addr_policy_get_canonical_entry(&policy));
smartlist_add(tmp, addr_policy_get_canonical_entry(&newpolicy));
}
addr_policy_free(p);
});
......
......@@ -2337,13 +2337,13 @@ connection_or_flush_from_first_active_circuit(or_connection_t *conn, int max,
/* Calculate the exact time that this cell has spent in the queue. */
if (get_options()->CellStatistics && !CIRCUIT_IS_ORIGIN(circ)) {
struct timeval now;
struct timeval tvnow;
uint32_t flushed;
uint32_t cell_waiting_time;
insertion_time_queue_t *it_queue = queue->insertion_times;
tor_gettimeofday_cached(&now);
flushed = (uint32_t)((now.tv_sec % SECONDS_IN_A_DAY) * 100L +
(uint32_t)now.tv_usec / (uint32_t)10000L);
tor_gettimeofday_cached(&tvnow);
flushed = (uint32_t)((tvnow.tv_sec % SECONDS_IN_A_DAY) * 100L +
(uint32_t)tvnow.tv_usec / (uint32_t)10000L);
if (!it_queue || !it_queue->first) {
log_info(LD_GENERAL, "Cannot determine insertion time of cell. "
"Looks like the CellStatistics option was "
......
......@@ -2274,6 +2274,8 @@ hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest,
return 0;
if (nn_char == '=' || nn_char == '~') {
if (!nickname)
return 0;
if (strcasecmp(nn_buf, nickname))
return 0;
if (nn_char == '=' && !is_named)
......
......@@ -3512,10 +3512,10 @@ networkstatus_parse_detached_signatures(const char *s, const char *eos)
siglist = detached_get_signatures(sigs, flavor);
is_duplicate = 0;
SMARTLIST_FOREACH(siglist, document_signature_t *, s, {
if (s->alg == alg &&
tor_memeq(id_digest, s->identity_digest, DIGEST_LEN) &&
tor_memeq(sk_digest, s->signing_key_digest, DIGEST_LEN)) {
SMARTLIST_FOREACH(siglist, document_signature_t *, dsig, {
if (dsig->alg == alg &&
tor_memeq(id_digest, dsig->identity_digest, DIGEST_LEN) &&
tor_memeq(sk_digest, dsig->signing_key_digest, DIGEST_LEN)) {
is_duplicate = 1;
}
});
......
......@@ -1318,7 +1318,10 @@ main(int c, const char **v)
}
options->command = CMD_RUN_UNITTESTS;
crypto_global_init(0, NULL, NULL);
if (crypto_global_init(0, NULL, NULL)) {
printf("Can't initialize crypto subsystem; exiting.\n");
return 1;
}
rep_hist_init();
network_init();
setup_directory();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment