mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-20 02:09:24 +01:00
Refactor some code and add some asserts based on scanner results.
svn:r16783
This commit is contained in:
parent
a345506672
commit
339f094056
@ -521,7 +521,6 @@ int
|
||||
tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime)
|
||||
{
|
||||
crypto_pk_env_t *rsa = NULL;
|
||||
crypto_dh_env_t *dh = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
tor_tls_context_t *result = NULL;
|
||||
X509 *cert = NULL, *idcert = NULL;
|
||||
@ -597,9 +596,11 @@ tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime)
|
||||
pkey = NULL;
|
||||
if (!SSL_CTX_check_private_key(result->ctx))
|
||||
goto error;
|
||||
dh = crypto_dh_new();
|
||||
SSL_CTX_set_tmp_dh(result->ctx, _crypto_dh_env_get_dh(dh));
|
||||
crypto_dh_free(dh);
|
||||
{
|
||||
crypto_dh_env_t *dh = crypto_dh_new();
|
||||
SSL_CTX_set_tmp_dh(result->ctx, _crypto_dh_env_get_dh(dh));
|
||||
crypto_dh_free(dh);
|
||||
}
|
||||
SSL_CTX_set_verify(result->ctx, SSL_VERIFY_PEER,
|
||||
always_accept_verify_cb);
|
||||
/* let us realloc bufs that we're writing from */
|
||||
@ -625,8 +626,6 @@ tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime)
|
||||
EVP_PKEY_free(pkey);
|
||||
if (rsa)
|
||||
crypto_free_pk_env(rsa);
|
||||
if (dh)
|
||||
crypto_dh_free(dh);
|
||||
if (result)
|
||||
tor_tls_context_decref(result);
|
||||
if (cert)
|
||||
|
@ -4500,24 +4500,24 @@ write_configuration_file(const char *fname, or_options_t *options)
|
||||
int rename_old = 0, r;
|
||||
size_t len;
|
||||
|
||||
if (fname) {
|
||||
switch (file_status(fname)) {
|
||||
case FN_FILE:
|
||||
old_val = read_file_to_str(fname, 0, NULL);
|
||||
if (strcmpstart(old_val, GENERATED_FILE_PREFIX)) {
|
||||
rename_old = 1;
|
||||
}
|
||||
tor_free(old_val);
|
||||
break;
|
||||
case FN_NOENT:
|
||||
break;
|
||||
case FN_ERROR:
|
||||
case FN_DIR:
|
||||
default:
|
||||
log_warn(LD_CONFIG,
|
||||
"Config file \"%s\" is not a file? Failing.", fname);
|
||||
return -1;
|
||||
}
|
||||
tor_assert(fname);
|
||||
|
||||
switch (file_status(fname)) {
|
||||
case FN_FILE:
|
||||
old_val = read_file_to_str(fname, 0, NULL);
|
||||
if (strcmpstart(old_val, GENERATED_FILE_PREFIX)) {
|
||||
rename_old = 1;
|
||||
}
|
||||
tor_free(old_val);
|
||||
break;
|
||||
case FN_NOENT:
|
||||
break;
|
||||
case FN_ERROR:
|
||||
case FN_DIR:
|
||||
default:
|
||||
log_warn(LD_CONFIG,
|
||||
"Config file \"%s\" is not a file? Failing.", fname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(new_conf = options_dump(options, 1))) {
|
||||
|
@ -3021,6 +3021,8 @@ write_stream_target_to_buf(edge_connection_t *conn, char *buf, size_t len)
|
||||
if (conn->chosen_exit_name)
|
||||
if (tor_snprintf(buf2, sizeof(buf2), ".%s.exit", conn->chosen_exit_name)<0)
|
||||
return -1;
|
||||
if (!conn->socks_request)
|
||||
return -1;
|
||||
if (tor_snprintf(buf, len, "%s%s%s:%d",
|
||||
conn->socks_request->address,
|
||||
conn->chosen_exit_name ? buf2 : "",
|
||||
|
@ -925,6 +925,7 @@ directory_send_command(dir_connection_t *conn,
|
||||
url = tor_strdup("/tor/running-routers");
|
||||
break;
|
||||
case DIR_PURPOSE_FETCH_NETWORKSTATUS:
|
||||
tor_assert(resource);
|
||||
httpcommand = "GET";
|
||||
len = strlen(resource)+32;
|
||||
url = tor_malloc(len);
|
||||
@ -962,12 +963,14 @@ directory_send_command(dir_connection_t *conn,
|
||||
url = tor_strdup("/tor/status-vote/next/consensus-signatures.z");
|
||||
break;
|
||||
case DIR_PURPOSE_FETCH_SERVERDESC:
|
||||
tor_assert(resource);
|
||||
httpcommand = "GET";
|
||||
len = strlen(resource)+32;
|
||||
url = tor_malloc(len);
|
||||
tor_snprintf(url, len, "/tor/server/%s", resource);
|
||||
break;
|
||||
case DIR_PURPOSE_FETCH_EXTRAINFO:
|
||||
tor_assert(resource);
|
||||
httpcommand = "GET";
|
||||
len = strlen(resource)+32;
|
||||
url = tor_malloc(len);
|
||||
|
@ -221,7 +221,6 @@ crypto_pk_env_t *
|
||||
init_key_from_file(const char *fname, int generate, int severity)
|
||||
{
|
||||
crypto_pk_env_t *prkey = NULL;
|
||||
FILE *file = NULL;
|
||||
|
||||
if (!(prkey = crypto_new_pk_env())) {
|
||||
log(severity, LD_GENERAL,"Error constructing key");
|
||||
@ -279,8 +278,6 @@ init_key_from_file(const char *fname, int generate, int severity)
|
||||
error:
|
||||
if (prkey)
|
||||
crypto_free_pk_env(prkey);
|
||||
if (file)
|
||||
fclose(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user