aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-09-05 21:19:53 +0000
committerNick Mathewson <nickm@torproject.org>2008-09-05 21:19:53 +0000
commit339f09405608ac5277fc0f43f459352967e7803d (patch)
treecc5d0348b4046acd4b81ef3cf5a881663da1b80b /src
parenta34550667298dcff6cbd7333288d71808b800b33 (diff)
downloadtor-339f09405608ac5277fc0f43f459352967e7803d.tar.gz
tor-339f09405608ac5277fc0f43f459352967e7803d.zip
Refactor some code and add some asserts based on scanner results.
svn:r16783
Diffstat (limited to 'src')
-rw-r--r--src/common/tortls.c11
-rw-r--r--src/or/config.c36
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/directory.c3
-rw-r--r--src/or/router.c3
5 files changed, 28 insertions, 27 deletions
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 67c68fe6d4..1032a53f25 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -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)
diff --git a/src/or/config.c b/src/or/config.c
index 4f7c752464..92a4a0dbeb 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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))) {
diff --git a/src/or/control.c b/src/or/control.c
index 9c3f749d6f..ac31f5d940 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -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 : "",
diff --git a/src/or/directory.c b/src/or/directory.c
index e7b37e4c1f..4f4d94af33 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -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);
diff --git a/src/or/router.c b/src/or/router.c
index 4c85a7b2ab..1132f9dca5 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -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;
}