aboutsummaryrefslogtreecommitdiff
path: root/src/or
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/or
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/or')
-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
4 files changed, 23 insertions, 21 deletions
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;
}