Refactor some code and add some asserts based on scanner results.

svn:r16783
This commit is contained in:
Nick Mathewson 2008-09-05 21:19:53 +00:00
parent a345506672
commit 339f094056
5 changed files with 28 additions and 27 deletions

View File

@ -521,7 +521,6 @@ int
tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime) tor_tls_context_new(crypto_pk_env_t *identity, unsigned int key_lifetime)
{ {
crypto_pk_env_t *rsa = NULL; crypto_pk_env_t *rsa = NULL;
crypto_dh_env_t *dh = NULL;
EVP_PKEY *pkey = NULL; EVP_PKEY *pkey = NULL;
tor_tls_context_t *result = NULL; tor_tls_context_t *result = NULL;
X509 *cert = NULL, *idcert = 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; pkey = NULL;
if (!SSL_CTX_check_private_key(result->ctx)) if (!SSL_CTX_check_private_key(result->ctx))
goto error; goto error;
dh = crypto_dh_new(); {
SSL_CTX_set_tmp_dh(result->ctx, _crypto_dh_env_get_dh(dh)); crypto_dh_env_t *dh = crypto_dh_new();
crypto_dh_free(dh); 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, SSL_CTX_set_verify(result->ctx, SSL_VERIFY_PEER,
always_accept_verify_cb); always_accept_verify_cb);
/* let us realloc bufs that we're writing from */ /* 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); EVP_PKEY_free(pkey);
if (rsa) if (rsa)
crypto_free_pk_env(rsa); crypto_free_pk_env(rsa);
if (dh)
crypto_dh_free(dh);
if (result) if (result)
tor_tls_context_decref(result); tor_tls_context_decref(result);
if (cert) if (cert)

View File

@ -4500,24 +4500,24 @@ write_configuration_file(const char *fname, or_options_t *options)
int rename_old = 0, r; int rename_old = 0, r;
size_t len; size_t len;
if (fname) { tor_assert(fname);
switch (file_status(fname)) {
case FN_FILE: switch (file_status(fname)) {
old_val = read_file_to_str(fname, 0, NULL); case FN_FILE:
if (strcmpstart(old_val, GENERATED_FILE_PREFIX)) { old_val = read_file_to_str(fname, 0, NULL);
rename_old = 1; if (strcmpstart(old_val, GENERATED_FILE_PREFIX)) {
} rename_old = 1;
tor_free(old_val); }
break; tor_free(old_val);
case FN_NOENT: break;
break; case FN_NOENT:
case FN_ERROR: break;
case FN_DIR: case FN_ERROR:
default: case FN_DIR:
log_warn(LD_CONFIG, default:
"Config file \"%s\" is not a file? Failing.", fname); log_warn(LD_CONFIG,
return -1; "Config file \"%s\" is not a file? Failing.", fname);
} return -1;
} }
if (!(new_conf = options_dump(options, 1))) { if (!(new_conf = options_dump(options, 1))) {

View File

@ -3021,6 +3021,8 @@ write_stream_target_to_buf(edge_connection_t *conn, char *buf, size_t len)
if (conn->chosen_exit_name) if (conn->chosen_exit_name)
if (tor_snprintf(buf2, sizeof(buf2), ".%s.exit", conn->chosen_exit_name)<0) if (tor_snprintf(buf2, sizeof(buf2), ".%s.exit", conn->chosen_exit_name)<0)
return -1; return -1;
if (!conn->socks_request)
return -1;
if (tor_snprintf(buf, len, "%s%s%s:%d", if (tor_snprintf(buf, len, "%s%s%s:%d",
conn->socks_request->address, conn->socks_request->address,
conn->chosen_exit_name ? buf2 : "", conn->chosen_exit_name ? buf2 : "",

View File

@ -925,6 +925,7 @@ directory_send_command(dir_connection_t *conn,
url = tor_strdup("/tor/running-routers"); url = tor_strdup("/tor/running-routers");
break; break;
case DIR_PURPOSE_FETCH_NETWORKSTATUS: case DIR_PURPOSE_FETCH_NETWORKSTATUS:
tor_assert(resource);
httpcommand = "GET"; httpcommand = "GET";
len = strlen(resource)+32; len = strlen(resource)+32;
url = tor_malloc(len); 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"); url = tor_strdup("/tor/status-vote/next/consensus-signatures.z");
break; break;
case DIR_PURPOSE_FETCH_SERVERDESC: case DIR_PURPOSE_FETCH_SERVERDESC:
tor_assert(resource);
httpcommand = "GET"; httpcommand = "GET";
len = strlen(resource)+32; len = strlen(resource)+32;
url = tor_malloc(len); url = tor_malloc(len);
tor_snprintf(url, len, "/tor/server/%s", resource); tor_snprintf(url, len, "/tor/server/%s", resource);
break; break;
case DIR_PURPOSE_FETCH_EXTRAINFO: case DIR_PURPOSE_FETCH_EXTRAINFO:
tor_assert(resource);
httpcommand = "GET"; httpcommand = "GET";
len = strlen(resource)+32; len = strlen(resource)+32;
url = tor_malloc(len); url = tor_malloc(len);

View File

@ -221,7 +221,6 @@ crypto_pk_env_t *
init_key_from_file(const char *fname, int generate, int severity) init_key_from_file(const char *fname, int generate, int severity)
{ {
crypto_pk_env_t *prkey = NULL; crypto_pk_env_t *prkey = NULL;
FILE *file = NULL;
if (!(prkey = crypto_new_pk_env())) { if (!(prkey = crypto_new_pk_env())) {
log(severity, LD_GENERAL,"Error constructing key"); log(severity, LD_GENERAL,"Error constructing key");
@ -279,8 +278,6 @@ init_key_from_file(const char *fname, int generate, int severity)
error: error:
if (prkey) if (prkey)
crypto_free_pk_env(prkey); crypto_free_pk_env(prkey);
if (file)
fclose(file);
return NULL; return NULL;
} }