diff options
Diffstat (limited to 'src')
39 files changed, 199 insertions, 183 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index 06446ba050..7298ec084e 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1327,7 +1327,7 @@ crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out) /** Compute all digests of the DER encoding of <b>pk</b>, and store them * in <b>digests_out</b>. Return 0 on success, -1 on failure. */ int -crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out) +crypto_pk_get_common_digests(crypto_pk_t *pk, common_digests_t *digests_out) { unsigned char *buf = NULL; int len; @@ -1335,7 +1335,7 @@ crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out) len = i2d_RSAPublicKey(pk->key, &buf); if (len < 0 || buf == NULL) return -1; - if (crypto_digest_all(digests_out, (char*)buf, len) < 0) { + if (crypto_common_digests(digests_out, (char*)buf, len) < 0) { OPENSSL_free(buf); return -1; } @@ -1649,33 +1649,19 @@ crypto_digest512(char *digest, const char *m, size_t len, == -1); } -/** Set the digests_t in <b>ds_out</b> to contain every digest on the +/** Set the common_digests_t in <b>ds_out</b> to contain every digest on the * <b>len</b> bytes in <b>m</b> that we know how to compute. Return 0 on * success, -1 on failure. */ int -crypto_digest_all(digests_t *ds_out, const char *m, size_t len) +crypto_common_digests(common_digests_t *ds_out, const char *m, size_t len) { - int i; tor_assert(ds_out); memset(ds_out, 0, sizeof(*ds_out)); if (crypto_digest(ds_out->d[DIGEST_SHA1], m, len) < 0) return -1; - for (i = DIGEST_SHA256; i < N_DIGEST_ALGORITHMS; ++i) { - switch (i) { - case DIGEST_SHA256: /* FALLSTHROUGH */ - case DIGEST_SHA3_256: - if (crypto_digest256(ds_out->d[i], m, len, i) < 0) - return -1; - break; - case DIGEST_SHA512: - case DIGEST_SHA3_512: /* FALLSTHROUGH */ - if (crypto_digest512(ds_out->d[i], m, len, i) < 0) - return -1; - break; - default: - return -1; - } - } + if (crypto_digest256(ds_out->d[DIGEST_SHA256], m, len, DIGEST_SHA256) < 0) + return -1; + return 0; } diff --git a/src/common/crypto.h b/src/common/crypto.h index 74b88bcd4a..2da7f9e2a1 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -100,8 +100,9 @@ typedef enum { DIGEST_SHA3_512 = 4, } digest_algorithm_t; #define N_DIGEST_ALGORITHMS (DIGEST_SHA3_512+1) +#define N_COMMON_DIGEST_ALGORITHMS (DIGEST_SHA256+1) -/** A set of all the digests we know how to compute, taken on a single +/** A set of all the digests we commonly compute, taken on a single * string. Any digests that are shorter than 512 bits are right-padded * with 0 bits. * @@ -110,8 +111,8 @@ typedef enum { * once. **/ typedef struct { - char d[N_DIGEST_ALGORITHMS][DIGEST512_LEN]; -} digests_t; + char d[N_COMMON_DIGEST_ALGORITHMS][DIGEST256_LEN]; +} common_digests_t; typedef struct crypto_pk_t crypto_pk_t; typedef struct crypto_cipher_t crypto_cipher_t; @@ -191,7 +192,8 @@ int crypto_pk_private_hybrid_decrypt(crypto_pk_t *env, char *to, int crypto_pk_asn1_encode(crypto_pk_t *pk, char *dest, size_t dest_len); crypto_pk_t *crypto_pk_asn1_decode(const char *str, size_t len); int crypto_pk_get_digest(const crypto_pk_t *pk, char *digest_out); -int crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out); +int crypto_pk_get_common_digests(crypto_pk_t *pk, + common_digests_t *digests_out); int crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out,int add_space); int crypto_pk_get_hashed_fingerprint(crypto_pk_t *pk, char *fp_out); @@ -220,7 +222,7 @@ int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm); int crypto_digest512(char *digest, const char *m, size_t len, digest_algorithm_t algorithm); -int crypto_digest_all(digests_t *ds_out, const char *m, size_t len); +int crypto_common_digests(common_digests_t *ds_out, const char *m, size_t len); struct smartlist_t; void crypto_digest_smartlist_prefix(char *digest_out, size_t len_out, const char *prepend, diff --git a/src/common/tortls.c b/src/common/tortls.c index 827abc428d..8f2dc4bf2c 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -685,13 +685,13 @@ MOCK_IMPL(STATIC tor_x509_cert_t *, cert->cert = x509_cert; - crypto_digest_all(&cert->cert_digests, + crypto_common_digests(&cert->cert_digests, (char*)cert->encoded, cert->encoded_len); if ((pkey = X509_get_pubkey(x509_cert)) && (rsa = EVP_PKEY_get1_RSA(pkey))) { crypto_pk_t *pk = crypto_new_pk_from_rsa_(rsa); - crypto_pk_get_all_digests(pk, &cert->pkey_digests); + crypto_pk_get_common_digests(pk, &cert->pkey_digests); cert->pkey_digests_set = 1; crypto_pk_free(pk); EVP_PKEY_free(pkey); @@ -754,7 +754,7 @@ tor_x509_cert_get_der(const tor_x509_cert_t *cert, /** Return a set of digests for the public key in <b>cert</b>, or NULL if this * cert's public key is not one we know how to take the digest of. */ -const digests_t * +const common_digests_t * tor_x509_cert_get_id_digests(const tor_x509_cert_t *cert) { if (cert->pkey_digests_set) @@ -764,7 +764,7 @@ tor_x509_cert_get_id_digests(const tor_x509_cert_t *cert) } /** Return a set of digests for the public key in <b>cert</b>. */ -const digests_t * +const common_digests_t * tor_x509_cert_get_cert_digests(const tor_x509_cert_t *cert) { return &cert->cert_digests; diff --git a/src/common/tortls.h b/src/common/tortls.h index 7239eb9fd7..336115ae6b 100644 --- a/src/common/tortls.h +++ b/src/common/tortls.h @@ -82,8 +82,8 @@ struct tor_x509_cert_t { uint8_t *encoded; size_t encoded_len; unsigned pkey_digests_set : 1; - digests_t cert_digests; - digests_t pkey_digests; + common_digests_t cert_digests; + common_digests_t pkey_digests; }; /** Holds a SSL object and its associated data. Members are only @@ -238,8 +238,10 @@ tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate, size_t certificate_len); void tor_x509_cert_get_der(const tor_x509_cert_t *cert, const uint8_t **encoded_out, size_t *size_out); -const digests_t *tor_x509_cert_get_id_digests(const tor_x509_cert_t *cert); -const digests_t *tor_x509_cert_get_cert_digests(const tor_x509_cert_t *cert); +const common_digests_t *tor_x509_cert_get_id_digests( + const tor_x509_cert_t *cert); +const common_digests_t *tor_x509_cert_get_cert_digests( + const tor_x509_cert_t *cert); int tor_tls_get_my_certs(int server, const tor_x509_cert_t **link_cert_out, const tor_x509_cert_t **id_cert_out); diff --git a/src/common/util.c b/src/common/util.c index fda5993edf..488f1b6ca8 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2080,7 +2080,7 @@ check_private_dir(const char *dirname, cpd_check_t check, */ tor_assert(dirname); - /* Open directory. + /* Open directory. * O_NOFOLLOW to ensure that it does not follow symbolic links */ fd = open(sandbox_intern_string(dirname), O_NOFOLLOW); @@ -2122,7 +2122,7 @@ check_private_dir(const char *dirname, cpd_check_t check, if ( fd == -1 ) return -1; - } else if (!(check & CPD_CHECK)) { + } else if (!(check & CPD_CHECK)) { log_warn(LD_FS, "Directory %s does not exist.", dirname); return -1; } diff --git a/src/common/util.h b/src/common/util.h index d05ffa7d10..d42b5b2b0d 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -29,6 +29,9 @@ #ifndef O_TEXT #define O_TEXT 0 #endif +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0 +#endif /* Replace assert() with a variant that sends failures to the log before * calling assert() normally. diff --git a/src/ext/trunnel/trunnel-impl.h b/src/ext/trunnel/trunnel-impl.h index a97caf282f..dfe5f89e1a 100644 --- a/src/ext/trunnel/trunnel-impl.h +++ b/src/ext/trunnel/trunnel-impl.h @@ -1,4 +1,4 @@ -/* trunnel-impl.h -- copied from Trunnel v1.4.3 +/* trunnel-impl.h -- copied from Trunnel v1.4.4 * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/ext/trunnel/trunnel.c b/src/ext/trunnel/trunnel.c index 25a46d9022..0ed75aa9a4 100644 --- a/src/ext/trunnel/trunnel.c +++ b/src/ext/trunnel/trunnel.c @@ -1,4 +1,4 @@ -/* trunnel.c -- copied from Trunnel v1.4.3 +/* trunnel.c -- copied from Trunnel v1.4.4 * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/ext/trunnel/trunnel.h b/src/ext/trunnel/trunnel.h index 6140a3953f..62e87ee50c 100644 --- a/src/ext/trunnel/trunnel.h +++ b/src/ext/trunnel/trunnel.h @@ -1,4 +1,4 @@ -/* trunnel.h -- copied from Trunnel v1.4.3 +/* trunnel.h -- copied from Trunnel v1.4.4 * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/or/channeltls.c b/src/or/channeltls.c index f0333e8da8..016ef75456 100644 --- a/src/or/channeltls.c +++ b/src/or/channeltls.c @@ -1819,7 +1819,8 @@ channel_tls_process_certs_cell(var_cell_t *cell, channel_tls_t *chan) chan->conn->handshake_state->authenticated = 1; { - const digests_t *id_digests = tor_x509_cert_get_id_digests(id_cert); + const common_digests_t *id_digests = + tor_x509_cert_get_id_digests(id_cert); crypto_pk_t *identity_rcvd; if (!id_digests) ERR("Couldn't compute digests for key in ID cert"); @@ -2109,7 +2110,7 @@ channel_tls_process_authenticate_cell(var_cell_t *cell, channel_tls_t *chan) { crypto_pk_t *identity_rcvd = tor_tls_cert_get_key(chan->conn->handshake_state->id_cert); - const digests_t *id_digests = + const common_digests_t *id_digests = tor_x509_cert_get_id_digests(chan->conn->handshake_state->id_cert); /* This must exist; we checked key type when reading the cert. */ diff --git a/src/or/config.c b/src/or/config.c index 5273d5ade7..ba02e9f180 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -6373,6 +6373,7 @@ parse_port_config(smartlist_t *out, tor_free(addrtmp); goto err; } + tor_free(addrtmp); } else { /* Try parsing integer port before address, because, who knows? "9050" might be a valid address. */ diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 29e8153d89..6f40e6a78e 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -2318,7 +2318,7 @@ connection_or_compute_authenticate_cell_body(or_connection_t *conn, { const tor_x509_cert_t *id_cert=NULL, *link_cert=NULL; - const digests_t *my_digests, *their_digests; + const common_digests_t *my_digests, *their_digests; const uint8_t *my_id, *their_id, *client_id, *server_id; if (tor_tls_get_my_certs(server, &link_cert, &id_cert)) goto err; diff --git a/src/or/control.c b/src/or/control.c index 2c0209ed85..55b287d27b 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -6384,6 +6384,7 @@ control_event_hs_descriptor_receive_end(const char *action, */ void control_event_hs_descriptor_upload_end(const char *action, + const char *onion_address, const char *id_digest, const char *reason) { @@ -6400,8 +6401,9 @@ control_event_hs_descriptor_upload_end(const char *action, } send_control_event(EVENT_HS_DESC, - "650 HS_DESC %s UNKNOWN UNKNOWN %s%s\r\n", + "650 HS_DESC %s %s UNKNOWN %s%s\r\n", action, + rend_hsaddress_str_or_unknown(onion_address), node_describe_longname_by_id(id_digest), reason_field ? reason_field : ""); @@ -6431,14 +6433,17 @@ control_event_hs_descriptor_received(const char *onion_address, * called when we successfully uploaded a hidden service descriptor. */ void -control_event_hs_descriptor_uploaded(const char *id_digest) +control_event_hs_descriptor_uploaded(const char *id_digest, + const char *onion_address) { if (!id_digest) { log_warn(LD_BUG, "Called with id_digest==%p", id_digest); return; } - control_event_hs_descriptor_upload_end("UPLOADED", id_digest, NULL); + + control_event_hs_descriptor_upload_end("UPLOADED", onion_address, + id_digest, NULL); } /** Send HS_DESC event to inform controller that query <b>rend_query</b> @@ -6500,6 +6505,7 @@ control_event_hs_descriptor_content(const char *onion_address, */ void control_event_hs_descriptor_upload_failed(const char *id_digest, + const char *onion_address, const char *reason) { if (!id_digest) { @@ -6507,7 +6513,7 @@ control_event_hs_descriptor_upload_failed(const char *id_digest, id_digest); return; } - control_event_hs_descriptor_upload_end("UPLOAD_FAILED", + control_event_hs_descriptor_upload_end("UPLOAD_FAILED", onion_address, id_digest, reason); } diff --git a/src/or/control.h b/src/or/control.h index 1f8e2bcdc6..c5191f93bb 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -129,16 +129,19 @@ void control_event_hs_descriptor_receive_end(const char *action, const char *id_digest, const char *reason); void control_event_hs_descriptor_upload_end(const char *action, + const char *onion_address, const char *hs_dir, const char *reason); void control_event_hs_descriptor_received(const char *onion_address, const rend_data_t *rend_data, const char *id_digest); -void control_event_hs_descriptor_uploaded(const char *hs_dir); +void control_event_hs_descriptor_uploaded(const char *hs_dir, + const char *onion_address); void control_event_hs_descriptor_failed(const rend_data_t *rend_data, const char *id_digest, const char *reason); void control_event_hs_descriptor_upload_failed(const char *hs_dir, + const char *onion_address, const char *reason); void control_event_hs_descriptor_content(const char *onion_address, const char *desc_id, diff --git a/src/or/directory.c b/src/or/directory.c index ecf6da8ac1..399752a02c 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -2363,17 +2363,23 @@ connection_dir_client_reached_eof(dir_connection_t *conn) if (conn->base_.purpose == DIR_PURPOSE_UPLOAD_RENDDESC_V2) { #define SEND_HS_DESC_UPLOAD_FAILED_EVENT(reason) ( \ - control_event_hs_descriptor_upload_failed(conn->identity_digest, \ - reason) ) + control_event_hs_descriptor_upload_failed( \ + conn->identity_digest, \ + conn->rend_data->onion_address, \ + reason) ) log_info(LD_REND,"Uploaded rendezvous descriptor (status %d " "(%s))", status_code, escaped(reason)); + /* Without the rend data, we'll have a problem identifying what has been + * uploaded for which service. */ + tor_assert(conn->rend_data); switch (status_code) { case 200: log_info(LD_REND, "Uploading rendezvous descriptor: finished with status " "200 (%s)", escaped(reason)); - control_event_hs_descriptor_uploaded(conn->identity_digest); + control_event_hs_descriptor_uploaded(conn->identity_digest, + conn->rend_data->onion_address); rend_service_desc_has_uploaded(conn->rend_data); break; case 400: diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 3771818457..ee85cebf7e 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1230,7 +1230,7 @@ free_cached_dir_(void *_d) void dirserv_set_cached_consensus_networkstatus(const char *networkstatus, const char *flavor_name, - const digests_t *digests, + const common_digests_t *digests, time_t published) { cached_dir_t *new_networkstatus; @@ -1239,7 +1239,7 @@ dirserv_set_cached_consensus_networkstatus(const char *networkstatus, cached_consensuses = strmap_new(); new_networkstatus = new_cached_dir(tor_strdup(networkstatus), published); - memcpy(&new_networkstatus->digests, digests, sizeof(digests_t)); + memcpy(&new_networkstatus->digests, digests, sizeof(common_digests_t)); old_networkstatus = strmap_set(cached_consensuses, flavor_name, new_networkstatus); if (old_networkstatus) diff --git a/src/or/dirserv.h b/src/or/dirserv.h index d07339bc12..df23450ef9 100644 --- a/src/or/dirserv.h +++ b/src/or/dirserv.h @@ -63,9 +63,9 @@ int directory_too_idle_to_fetch_descriptors(const or_options_t *options, cached_dir_t *dirserv_get_consensus(const char *flavor_name); void dirserv_set_cached_consensus_networkstatus(const char *consensus, - const char *flavor_name, - const digests_t *digests, - time_t published); + const char *flavor_name, + const common_digests_t *digests, + time_t published); void dirserv_clear_old_networkstatuses(time_t cutoff); int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key, const char **msg, diff --git a/src/or/dirvote.c b/src/or/dirvote.c index b61b33af79..80e4c330ce 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -2114,7 +2114,7 @@ networkstatus_add_detached_signatures(networkstatus_t *target, /** Make sure all the digests we know match, and at least one matches. */ { - digests_t *digests = strmap_get(sigs->digests, flavor); + common_digests_t *digests = strmap_get(sigs->digests, flavor); int n_matches = 0; int alg; if (!digests) { diff --git a/src/or/microdesc.c b/src/or/microdesc.c index dc23bcb632..900a50eb41 100644 --- a/src/or/microdesc.c +++ b/src/or/microdesc.c @@ -840,7 +840,7 @@ microdesc_list_missing_digest256(networkstatus_t *ns, microdesc_cache_t *cache, /** Launch download requests for microdescriptors as appropriate. * * Specifically, we should launch download requests if we are configured to - * download mirodescriptors, and there are some microdescriptors listed the + * download mirodescriptors, and there are some microdescriptors listed in the * current microdesc consensus that we don't have, and either we never asked * for them, or we failed to download them but we're willing to retry. */ diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index f3a8276689..11ee618197 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1526,7 +1526,7 @@ networkstatus_set_current_consensus(const char *consensus, const unsigned dl_certs = !(flags & NSSET_DONT_DOWNLOAD_CERTS); const unsigned accept_obsolete = flags & NSSET_ACCEPT_OBSOLETE; const unsigned require_flavor = flags & NSSET_REQUIRE_FLAVOR; - const digests_t *current_digests = NULL; + const common_digests_t *current_digests = NULL; consensus_waiting_for_certs_t *waiting = NULL; time_t current_valid_after = 0; int free_consensus = 1; /* Free 'c' at the end of the function */ diff --git a/src/or/or.h b/src/or/or.h index f438212b31..6fd6dfc5fb 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1935,7 +1935,7 @@ typedef struct cached_dir_t { size_t dir_len; /**< Length of <b>dir</b> (not counting its NUL). */ size_t dir_z_len; /**< Length of <b>dir_z</b>. */ time_t published; /**< When was this object published. */ - digests_t digests; /**< Digests of this object (networkstatus only) */ + common_digests_t digests; /**< Digests of this object (networkstatus only) */ int refcnt; /**< Reference count for this cached_dir_t. */ } cached_dir_t; @@ -2573,7 +2573,7 @@ typedef struct networkstatus_t { struct authority_cert_t *cert; /**< Vote only: the voter's certificate. */ /** Digests of this document, as signed. */ - digests_t digests; + common_digests_t digests; /** List of router statuses, sorted by identity digest. For a vote, * the elements are vote_routerstatus_t; for a consensus, the elements diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c index d88bfca13a..210178dc1d 100644 --- a/src/or/routerkeys.c +++ b/src/or/routerkeys.c @@ -927,7 +927,7 @@ generate_ed_link_cert(const or_options_t *options, time_t now) return -1; } - const digests_t *digests = tor_x509_cert_get_cert_digests(link); + const common_digests_t *digests = tor_x509_cert_get_cert_digests(link); if (link_cert_cert && ! EXPIRES_SOON(link_cert_cert, options->TestingLinkKeySlop) && @@ -972,7 +972,7 @@ should_make_new_ed_keys(const or_options_t *options, const time_t now) if (tor_tls_get_my_certs(1, &link, &id) < 0 || link == NULL) return 1; - const digests_t *digests = tor_x509_cert_get_cert_digests(link); + const common_digests_t *digests = tor_x509_cert_get_cert_digests(link); if (!fast_memeq(digests->d[DIGEST_SHA256], link_cert_cert->signed_key.pubkey, diff --git a/src/or/routerlist.c b/src/or/routerlist.c index f6662705dc..13ef081064 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -4452,7 +4452,7 @@ clear_dir_servers(void) /** For every current directory connection whose purpose is <b>purpose</b>, * and where the resource being downloaded begins with <b>prefix</b>, split * rest of the resource into base16 fingerprints (or base64 fingerprints if - * purpose==DIR_PURPPOSE_FETCH_MICRODESC), decode them, and set the + * purpose==DIR_PURPOSE_FETCH_MICRODESC), decode them, and set the * corresponding elements of <b>result</b> to a nonzero value. */ static void diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 3be43dcb8e..43c30a19ee 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -538,7 +538,7 @@ static int router_get_hash_impl(const char *s, size_t s_len, char *digest, char end_char, digest_algorithm_t alg); static int router_get_hashes_impl(const char *s, size_t s_len, - digests_t *digests, + common_digests_t *digests, const char *start_str, const char *end_str, char end_char); static void token_clear(directory_token_t *tok); @@ -638,7 +638,7 @@ router_get_router_hash(const char *s, size_t s_len, char *digest) /** Set <b>digests</b> to all the digests of the consensus document in * <b>s</b> */ int -router_get_networkstatus_v3_hashes(const char *s, digests_t *digests) +router_get_networkstatus_v3_hashes(const char *s, common_digests_t *digests) { return router_get_hashes_impl(s,strlen(s),digests, "network-status-version", @@ -2847,7 +2847,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out, smartlist_t *rs_tokens = NULL, *footer_tokens = NULL; networkstatus_voter_info_t *voter = NULL; networkstatus_t *ns = NULL; - digests_t ns_digests; + common_digests_t ns_digests; const char *cert, *end_of_header, *end_of_footer, *s_dup = s; directory_token_t *tok; int ok; @@ -3443,15 +3443,16 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out, return ns; } -/** Return the digests_t that holds the digests of the +/** Return the common_digests_t that holds the digests of the * <b>flavor_name</b>-flavored networkstatus according to the detached - * signatures document <b>sigs</b>, allocating a new digests_t as neeeded. */ -static digests_t * + * signatures document <b>sigs</b>, allocating a new common_digests_t as + * neeeded. */ +static common_digests_t * detached_get_digests(ns_detached_signatures_t *sigs, const char *flavor_name) { - digests_t *d = strmap_get(sigs->digests, flavor_name); + common_digests_t *d = strmap_get(sigs->digests, flavor_name); if (!d) { - d = tor_malloc_zero(sizeof(digests_t)); + d = tor_malloc_zero(sizeof(common_digests_t)); strmap_set(sigs->digests, flavor_name, d); } return d; @@ -3459,7 +3460,7 @@ detached_get_digests(ns_detached_signatures_t *sigs, const char *flavor_name) /** Return the list of signatures of the <b>flavor_name</b>-flavored * networkstatus according to the detached signatures document <b>sigs</b>, - * allocating a new digests_t as neeeded. */ + * allocating a new common_digests_t as neeeded. */ static smartlist_t * detached_get_signatures(ns_detached_signatures_t *sigs, const char *flavor_name) @@ -3481,7 +3482,7 @@ networkstatus_parse_detached_signatures(const char *s, const char *eos) * networkstatus_parse_vote_from_string(). */ directory_token_t *tok; memarea_t *area = NULL; - digests_t *digests; + common_digests_t *digests; smartlist_t *tokens = smartlist_new(); ns_detached_signatures_t *sigs = @@ -4444,7 +4445,7 @@ router_get_hash_impl(const char *s, size_t s_len, char *digest, /** As router_get_hash_impl, but compute all hashes. */ static int -router_get_hashes_impl(const char *s, size_t s_len, digests_t *digests, +router_get_hashes_impl(const char *s, size_t s_len, common_digests_t *digests, const char *start_str, const char *end_str, char end_c) { @@ -4453,7 +4454,7 @@ router_get_hashes_impl(const char *s, size_t s_len, digests_t *digests, &start,&end)<0) return -1; - if (crypto_digest_all(digests, start, end-start)) { + if (crypto_common_digests(digests, start, end-start)) { log_warn(LD_BUG,"couldn't compute digests"); return -1; } diff --git a/src/or/routerparse.h b/src/or/routerparse.h index 99fd52866c..723d5d8945 100644 --- a/src/or/routerparse.h +++ b/src/or/routerparse.h @@ -14,7 +14,8 @@ int router_get_router_hash(const char *s, size_t s_len, char *digest); int router_get_dir_hash(const char *s, char *digest); -int router_get_networkstatus_v3_hashes(const char *s, digests_t *digests); +int router_get_networkstatus_v3_hashes(const char *s, + common_digests_t *digests); int router_get_extrainfo_hash(const char *s, size_t s_len, char *digest); #define DIROBJ_MAX_SIG_LEN 256 char *router_get_dirobj_signature(const char *digest, diff --git a/src/test/test_address.c b/src/test/test_address.c index 3b17b23571..748dfc5a68 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -297,7 +297,9 @@ test_address_get_if_addrs_ifaddrs(void *arg) } done: - SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t)); + if (results) { + SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t)); + } smartlist_free(results); return; } diff --git a/src/test/test_config.c b/src/test/test_config.c index 85bedd62c9..6be503abc5 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -3860,7 +3860,6 @@ test_config_parse_port_config__ports__no_ports_given(void *data) int ret; smartlist_t *slout = NULL; port_cfg_t *port_cfg = NULL; - config_line_t *config_port_invalid = NULL, *config_port_valid = NULL; slout = smartlist_new(); @@ -3918,8 +3917,6 @@ test_config_parse_port_config__ports__no_ports_given(void *data) done: smartlist_free(slout); - tor_free(config_port_invalid); - tor_free(config_port_valid); } static void @@ -3941,7 +3938,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(ret, OP_EQ, -1); // Test error when encounters an empty unix domain specification - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; config_port_invalid = mock_config_line("DNSPort", "unix:"); ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL, 0, 0); @@ -3971,7 +3968,7 @@ test_config_parse_port_config__ports__ports_given(void *data) // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets, // this makes no sense - it should be fixed) - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; config_port_invalid = mock_config_line("DNSPort", "unix:/tmp/foo/bar NoIPv4Traffic"); ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", @@ -3981,7 +3978,7 @@ test_config_parse_port_config__ports__ports_given(void *data) // Test success with no ipv4 but take ipv6 (for unix domain sockets, this // makes no sense - it should be fixed) - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar " "NoIPv4Traffic IPv6Traffic"); @@ -4000,7 +3997,7 @@ test_config_parse_port_config__ports__ports_given(void *data) // Test success with both ipv4 and ipv6 (for unix domain sockets, // this makes no sense - it should be fixed) - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar " "IPv4Traffic IPv6Traffic"); @@ -4018,28 +4015,28 @@ test_config_parse_port_config__ports__ports_given(void *data) #endif // Test failure if we specify world writable for an IP Port - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; config_port_invalid = mock_config_line("DNSPort", "42 WorldWritable"); ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0); tt_int_op(ret, OP_EQ, -1); // Test failure if we specify group writable for an IP Port - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; config_port_invalid = mock_config_line("DNSPort", "42 GroupWritable"); ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0); tt_int_op(ret, OP_EQ, -1); // Test success with only a port (this will fail without a default address) - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; config_port_valid = mock_config_line("DNSPort", "42"); ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0); tt_int_op(ret, OP_EQ, 0); // Test success with only a port and isolate destination port - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IsolateDestPort"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4051,7 +4048,7 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT | ISO_DESTPORT); // Test success with a negative isolate destination port, and plural - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 NoIsolateDestPorts"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4063,7 +4060,7 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT & ~ISO_DESTPORT); // Test success with isolate destination address - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IsolateDestAddr"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4075,7 +4072,7 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT | ISO_DESTADDR); // Test success with isolate socks AUTH - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IsolateSOCKSAuth"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4087,7 +4084,7 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT | ISO_SOCKSAUTH); // Test success with isolate client protocol - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IsolateClientProtocol"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4099,7 +4096,7 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT | ISO_CLIENTPROTO); // Test success with isolate client address - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IsolateClientAddr"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4111,14 +4108,14 @@ test_config_parse_port_config__ports__ports_given(void *data) ISO_DEFAULT | ISO_CLIENTADDR); // Test success with ignored unknown options - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; config_port_valid = mock_config_line("DNSPort", "42 ThisOptionDoesntExist"); ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0); tt_int_op(ret, OP_EQ, 0); // Test success with no isolate socks AUTH - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 NoIsolateSOCKSAuth"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4129,7 +4126,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.socks_prefer_no_auth, OP_EQ, 1); // Test success with prefer ipv6 - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", @@ -4141,7 +4138,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.prefer_ipv6, OP_EQ, 1); // Test success with cache ipv4 DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 CacheIPv4DNS"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4153,7 +4150,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0); // Test success with cache ipv6 DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 CacheIPv6DNS"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4165,7 +4162,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1); // Test success with no cache ipv4 DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 NoCacheIPv4DNS"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4177,7 +4174,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0); // Test success with cache DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 CacheDNS"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4189,7 +4186,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1); // Test success with use cached ipv4 DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 UseIPv4Cache"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4201,7 +4198,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 0); // Test success with use cached ipv6 DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 UseIPv6Cache"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4213,7 +4210,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1); // Test success with use cached DNS - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 UseDNSCache"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4225,7 +4222,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1); // Test success with not preferring ipv6 automap - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 NoPreferIPv6Automap"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4236,7 +4233,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.prefer_ipv6_virtaddr, OP_EQ, 0); // Test success with prefer SOCKS no auth - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 PreferSOCKSNoAuth"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4247,8 +4244,8 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.socks_prefer_no_auth, OP_EQ, 1); // Test failure with both a zero port and a non-zero port - tor_free(config_port_invalid); - tor_free(config_port_valid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "0"); config_port_valid = mock_config_line("DNSPort", "42"); @@ -4283,7 +4280,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(ret, OP_EQ, 0); // Test success with both ipv4 and ipv6 but without stream options - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic " "IPv6Traffic"); @@ -4298,7 +4295,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 0); // Test failure for a SessionGroup argument with invalid value - tor_free(config_port_invalid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid"); ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, @@ -4309,7 +4306,7 @@ test_config_parse_port_config__ports__ports_given(void *data) // Potential bug. // Test failure for a SessionGroup argument with valid value but with stream // options allowed - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123"); ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, @@ -4317,7 +4314,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(ret, OP_EQ, -1); // Test failure for more than one SessionGroup argument - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 " "SessionGroup=321"); @@ -4326,7 +4323,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(ret, OP_EQ, -1); // Test success with a sessiongroup options - tor_free(config_port_valid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4337,7 +4334,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(port_cfg->entry_cfg.session_group, OP_EQ, 1111122); // Test success with a zero unix domain socket, and doesnt add it to out - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "0"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4346,7 +4343,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(smartlist_len(slout), OP_EQ, 0); // Test success with a one unix domain socket, and doesnt add it to out - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "something"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4358,7 +4355,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_str_op(port_cfg->unix_addr, OP_EQ, "something"); // Test success with a port of auto - it uses the default address - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "auto"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4371,7 +4368,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_assert(tor_addr_eq(&port_cfg->addr, &addr)) // Test success with parsing both an address and an auto port - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "127.0.0.122:auto"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4384,14 +4381,14 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_assert(tor_addr_eq(&port_cfg->addr, &addr)) // Test failure when asked to parse an invalid address followed by auto - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; config_port_invalid = mock_config_line("DNSPort", "invalidstuff!!:auto"); ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0); tt_int_op(ret, OP_EQ, -1); // Test success with parsing both an address and a real port - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "127.0.0.123:656"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, @@ -4404,7 +4401,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_assert(tor_addr_eq(&port_cfg->addr, &addr)) // Test failure if we can't parse anything at all - tor_free(config_port_invalid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "something wrong"); ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, @@ -4412,7 +4409,7 @@ test_config_parse_port_config__ports__ports_given(void *data) tt_int_op(ret, OP_EQ, -1); // Test failure if we find both an address, a port and an auto - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "127.0.1.0:123:auto"); ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, @@ -4421,7 +4418,7 @@ test_config_parse_port_config__ports__ports_given(void *data) // Test that default to group writeable default sets group writeable for // domain socket - tor_free(config_port_valid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", @@ -4438,8 +4435,8 @@ test_config_parse_port_config__ports__ports_given(void *data) done: smartlist_free(slout); - tor_free(config_port_invalid); - tor_free(config_port_valid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; + config_free_lines(config_port_valid); config_port_valid = NULL; } static void @@ -4454,7 +4451,7 @@ test_config_parse_port_config__ports__server_options(void *data) slout = smartlist_new(); // Test success with NoAdvertise option - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoAdvertise"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, @@ -4466,7 +4463,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 0); // Test success with NoListen option - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, @@ -4478,7 +4475,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1); // Test failure with both NoAdvertise and NoListen option - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen " "NoAdvertise"); @@ -4487,7 +4484,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(ret, OP_EQ, -1); // Test success with IPv4Only - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, @@ -4499,7 +4496,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 0); // Test success with IPv6Only - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, @@ -4511,7 +4508,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 1); // Test failure with both IPv4Only and IPv6Only - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only " "IPv4Only"); @@ -4520,7 +4517,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(ret, OP_EQ, -1); // Test success with invalid parameter - tor_free(config_port_valid); + config_free_lines(config_port_valid); config_port_valid = NULL; smartlist_clear(slout); config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown"); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, @@ -4529,7 +4526,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(smartlist_len(slout), OP_EQ, 1); // Test failure when asked to bind only to ipv6 but gets an ipv4 address - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only"); @@ -4538,7 +4535,7 @@ test_config_parse_port_config__ports__server_options(void *data) tt_int_op(ret, OP_EQ, -1); // Test failure when asked to bind only to ipv4 but gets an ipv6 address - tor_free(config_port_invalid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; smartlist_clear(slout); config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only"); ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, @@ -4547,8 +4544,8 @@ test_config_parse_port_config__ports__server_options(void *data) done: smartlist_free(slout); - tor_free(config_port_invalid); - tor_free(config_port_valid); + config_free_lines(config_port_invalid); config_port_invalid = NULL; + config_free_lines(config_port_valid); config_port_valid = NULL; } #define CONFIG_TEST(name, flags) \ diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index 671ae7d7b2..c6684e285e 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -1090,7 +1090,7 @@ test_crypto_digests(void *arg) { crypto_pk_t *k = NULL; ssize_t r; - digests_t pkey_digests; + common_digests_t pkey_digests; char digest[DIGEST_LEN]; (void)arg; @@ -1104,7 +1104,7 @@ test_crypto_digests(void *arg) tt_mem_op(hex_str(digest, DIGEST_LEN),OP_EQ, AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN); - r = crypto_pk_get_all_digests(k, &pkey_digests); + r = crypto_pk_get_common_digests(k, &pkey_digests); tt_mem_op(hex_str(pkey_digests.d[DIGEST_SHA1], DIGEST_LEN),OP_EQ, AUTHORITY_SIGNKEY_A_DIGEST, HEX_DIGEST_LEN); diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 83a8b8ccc6..72e619f9cd 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -1999,11 +1999,13 @@ test_a_networkstatus( tt_assert(con_md3); /* All three should have the same digest. */ - tt_mem_op(&con->digests,OP_EQ, &con2->digests, sizeof(digests_t)); - tt_mem_op(&con->digests,OP_EQ, &con3->digests, sizeof(digests_t)); + tt_mem_op(&con->digests,OP_EQ, &con2->digests, sizeof(common_digests_t)); + tt_mem_op(&con->digests,OP_EQ, &con3->digests, sizeof(common_digests_t)); - tt_mem_op(&con_md->digests,OP_EQ, &con_md2->digests, sizeof(digests_t)); - tt_mem_op(&con_md->digests,OP_EQ, &con_md3->digests, sizeof(digests_t)); + tt_mem_op(&con_md->digests,OP_EQ, &con_md2->digests, + sizeof(common_digests_t)); + tt_mem_op(&con_md->digests,OP_EQ, &con_md3->digests, + sizeof(common_digests_t)); /* Extract a detached signature from con3. */ detached_text1 = get_detached_sigs(con3, con_md3); @@ -2017,7 +2019,7 @@ test_a_networkstatus( tt_int_op(dsig1->fresh_until,OP_EQ, con3->fresh_until); tt_int_op(dsig1->valid_until,OP_EQ, con3->valid_until); { - digests_t *dsig_digests = strmap_get(dsig1->digests, "ns"); + common_digests_t *dsig_digests = strmap_get(dsig1->digests, "ns"); tt_assert(dsig_digests); tt_mem_op(dsig_digests->d[DIGEST_SHA1], OP_EQ, con3->digests.d[DIGEST_SHA1], DIGEST_LEN); diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c index e1ac50e66e..46d76734e0 100644 --- a/src/test/test_dir_handle_get.c +++ b/src/test/test_dir_handle_get.c @@ -1764,7 +1764,7 @@ static void status_vote_current_consensus_ns_test(char **header, char **body, size_t *body_len) { - digests_t digests; + common_digests_t digests; dir_connection_t *conn = NULL; #define NETWORK_STATUS "some network status string" @@ -2255,7 +2255,6 @@ status_vote_next_consensus_signatures_test(char **header, char **body, static void test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data) { - dir_connection_t *conn = NULL; char *header = NULL, *body = NULL; size_t body_used; (void) data; @@ -2266,7 +2265,6 @@ test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data) tt_str_op(NOT_FOUND, OP_EQ, header); done: - connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -2308,7 +2306,6 @@ test_dir_handle_get_status_vote_next_consensus_signatures(void* data) static void test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data) { - dir_connection_t *conn = NULL; char *header = NULL, *body = NULL; size_t body_used; (void) data; @@ -2328,7 +2325,6 @@ test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data) done: UNMOCK(get_options); NS_UNMOCK(dirvote_get_pending_detached_signatures); - connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); or_options_free(mock_options); mock_options = NULL; diff --git a/src/test/test_options.c b/src/test/test_options.c index 10ee1f962b..b2be8a9c65 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -242,6 +242,7 @@ test_have_enough_mem_for_dircache(void *arg) } tor_free(msg); + config_free_lines(cl); cl = NULL; configuration = "ORPort 8080\nDirCache 1\nBridgeRelay 1"; r = config_get_lines(configuration, &cl, 1); tt_int_op(r, OP_EQ, 0); @@ -264,6 +265,7 @@ test_have_enough_mem_for_dircache(void *arg) } tor_free(msg); + config_free_lines(cl); cl = NULL; configuration = "ORPort 8080\nDirCache 0"; r = config_get_lines(configuration, &cl, 1); tt_int_op(r, OP_EQ, 0); @@ -292,8 +294,8 @@ test_have_enough_mem_for_dircache(void *arg) if (msg) tor_free(msg); tor_free(dflt); - tor_free(opt); - tor_free(cl); + or_options_free(opt); + config_free_lines(cl); return; } diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c index eaf8a55ac0..31533d070f 100644 --- a/src/test/test_routerlist.c +++ b/src/test/test_routerlist.c @@ -130,7 +130,6 @@ construct_consensus(const char **consensus_text_md) crypto_pk_t *sign_skey_leg=NULL; time_t now = time(NULL); smartlist_t *votes = NULL; - addr_policy_t *pol1 = NULL, *pol2 = NULL, *pol3 = NULL; int n_vrs; tt_assert(!dir_common_authority_pk_init(&cert1, &cert2, &cert3, @@ -141,7 +140,7 @@ construct_consensus(const char **consensus_text_md) dir_common_construct_vote_1(&vote, cert1, sign_skey_1, &dir_common_gen_routerstatus_for_v3ns, &v1, &n_vrs, now, 1); - + networkstatus_vote_free(vote); tt_assert(v1); tt_int_op(n_vrs, ==, 4); tt_int_op(smartlist_len(v1->routerstatus_list), ==, 4); @@ -149,7 +148,7 @@ construct_consensus(const char **consensus_text_md) dir_common_construct_vote_2(&vote, cert2, sign_skey_2, &dir_common_gen_routerstatus_for_v3ns, &v2, &n_vrs, now, 1); - + networkstatus_vote_free(vote); tt_assert(v2); tt_int_op(n_vrs, ==, 4); tt_int_op(smartlist_len(v2->routerstatus_list), ==, 4); @@ -161,7 +160,7 @@ construct_consensus(const char **consensus_text_md) tt_assert(v3); tt_int_op(n_vrs, ==, 4); tt_int_op(smartlist_len(v3->routerstatus_list), ==, 4); - + networkstatus_vote_free(vote); votes = smartlist_new(); smartlist_add(votes, v1); smartlist_add(votes, v2); @@ -177,16 +176,10 @@ construct_consensus(const char **consensus_text_md) tt_assert(*consensus_text_md); done: - if (vote) - tor_free(vote); - if (voter) - tor_free(voter); - if (pol1) - tor_free(pol1); - if (pol2) - tor_free(pol2); - if (pol3) - tor_free(pol3); + tor_free(voter); + networkstatus_vote_free(v1); + networkstatus_vote_free(v2); + networkstatus_vote_free(v3); } static void diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c index 138485c971..28847d4611 100644 --- a/src/test/test_tortls.c +++ b/src/test/test_tortls.c @@ -539,10 +539,10 @@ test_tortls_x509_cert_get_id_digests(void *ignored) { (void)ignored; tor_x509_cert_t *cert; - digests_t *d; - const digests_t *res; + common_digests_t *d; + const common_digests_t *res; cert = tor_malloc_zero(sizeof(tor_x509_cert_t)); - d = tor_malloc_zero(sizeof(digests_t)); + d = tor_malloc_zero(sizeof(common_digests_t)); d->d[0][0] = 42; res = tor_x509_cert_get_id_digests(cert); diff --git a/src/trunnel/ed25519_cert.c b/src/trunnel/ed25519_cert.c index ee010dbff9..f495743667 100644 --- a/src/trunnel/ed25519_cert.c +++ b/src/trunnel/ed25519_cert.c @@ -1,4 +1,4 @@ -/* ed25519_cert.c -- generated by Trunnel v1.4.3. +/* ed25519_cert.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -289,7 +289,8 @@ ed25519_cert_extension_encode(uint8_t *output, const size_t avail, const ed25519 trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->un_unparsed.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->un_unparsed.elts_, elt_len); written += elt_len; ptr += elt_len; } break; @@ -374,7 +375,8 @@ ed25519_cert_extension_parse_into(ed25519_cert_extension_t *obj, const uint8_t * /* Parse u8 un_unparsed[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->un_unparsed, remaining, {}); obj->un_unparsed.n_ = remaining; - memcpy(obj->un_unparsed.elts_, ptr, remaining); + if (remaining) + memcpy(obj->un_unparsed.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; break; } diff --git a/src/trunnel/ed25519_cert.h b/src/trunnel/ed25519_cert.h index face810dbe..75a82d8aff 100644 --- a/src/trunnel/ed25519_cert.h +++ b/src/trunnel/ed25519_cert.h @@ -1,4 +1,4 @@ -/* ed25519_cert.h -- generated by by Trunnel v1.4.3. +/* ed25519_cert.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/trunnel/link_handshake.c b/src/trunnel/link_handshake.c index f9b55f0739..3ef7341ae9 100644 --- a/src/trunnel/link_handshake.c +++ b/src/trunnel/link_handshake.c @@ -1,4 +1,4 @@ -/* link_handshake.c -- generated by Trunnel v1.4.3. +/* link_handshake.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -537,7 +537,8 @@ certs_cell_cert_encode(uint8_t *output, const size_t avail, const certs_cell_cer trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->body.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->body.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -589,7 +590,8 @@ certs_cell_cert_parse_into(certs_cell_cert_t *obj, const uint8_t *input, const s CHECK_REMAINING(obj->cert_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->body, obj->cert_len, {}); obj->body.n_ = obj->cert_len; - memcpy(obj->body.elts_, ptr, obj->cert_len); + if (obj->cert_len) + memcpy(obj->body.elts_, ptr, obj->cert_len); ptr += obj->cert_len; remaining -= obj->cert_len; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; @@ -840,7 +842,8 @@ rsa_ed_crosscert_encode(uint8_t *output, const size_t avail, const rsa_ed_crossc trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->sig.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->sig.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -899,7 +902,8 @@ rsa_ed_crosscert_parse_into(rsa_ed_crosscert_t *obj, const uint8_t *input, const CHECK_REMAINING(obj->sig_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->sig, obj->sig_len, {}); obj->sig.n_ = obj->sig_len; - memcpy(obj->sig.elts_, ptr, obj->sig_len); + if (obj->sig_len) + memcpy(obj->sig.elts_, ptr, obj->sig_len); ptr += obj->sig_len; remaining -= obj->sig_len; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; @@ -1467,7 +1471,8 @@ auth1_encode(uint8_t *output, const size_t avail, const auth1_t *obj, const auth trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->sig.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->sig.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -1576,7 +1581,8 @@ auth1_parse_into(auth1_t *obj, const uint8_t *input, const size_t len_in, const /* Parse u8 sig[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->sig, remaining, {}); obj->sig.n_ = remaining; - memcpy(obj->sig.elts_, ptr, remaining); + if (remaining) + memcpy(obj->sig.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; trunnel_assert(ptr + remaining == input + len_in); return len_in - remaining; diff --git a/src/trunnel/link_handshake.h b/src/trunnel/link_handshake.h index 60bc28fa33..2749ec7dd4 100644 --- a/src/trunnel/link_handshake.h +++ b/src/trunnel/link_handshake.h @@ -1,4 +1,4 @@ -/* link_handshake.h -- generated by by Trunnel v1.4.3. +/* link_handshake.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ diff --git a/src/trunnel/pwbox.c b/src/trunnel/pwbox.c index a80fbb949b..9b348a9b30 100644 --- a/src/trunnel/pwbox.c +++ b/src/trunnel/pwbox.c @@ -1,4 +1,4 @@ -/* pwbox.c -- generated by Trunnel v1.4.3. +/* pwbox.c -- generated by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -362,7 +362,8 @@ pwbox_encoded_encode(uint8_t *output, size_t avail, const pwbox_encoded_t *obj) trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->skey_header.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->skey_header.elts_, elt_len); written += elt_len; ptr += elt_len; } @@ -380,7 +381,8 @@ pwbox_encoded_encode(uint8_t *output, size_t avail, const pwbox_encoded_t *obj) trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; - memcpy(ptr, obj->data.elts_, elt_len); + if (elt_len) + memcpy(ptr, obj->data.elts_, elt_len); written += elt_len; ptr += elt_len; } trunnel_assert(written <= avail); @@ -460,7 +462,8 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_ CHECK_REMAINING(obj->header_len, truncated); TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->skey_header, obj->header_len, {}); obj->skey_header.n_ = obj->header_len; - memcpy(obj->skey_header.elts_, ptr, obj->header_len); + if (obj->header_len) + memcpy(obj->skey_header.elts_, ptr, obj->header_len); ptr += obj->header_len; remaining -= obj->header_len; /* Parse u8 iv[16] */ @@ -476,7 +479,8 @@ pwbox_encoded_parse_into(pwbox_encoded_t *obj, const uint8_t *input, const size_ /* Parse u8 data[] */ TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->data, remaining, {}); obj->data.n_ = remaining; - memcpy(obj->data.elts_, ptr, remaining); + if (remaining) + memcpy(obj->data.elts_, ptr, remaining); ptr += remaining; remaining -= remaining; if (remaining != 0) goto fail; diff --git a/src/trunnel/pwbox.h b/src/trunnel/pwbox.h index c357932681..e69e2c1a0e 100644 --- a/src/trunnel/pwbox.h +++ b/src/trunnel/pwbox.h @@ -1,4 +1,4 @@ -/* pwbox.h -- generated by by Trunnel v1.4.3. +/* pwbox.h -- generated by by Trunnel v1.4.4. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ |