[or-cvs] r16783: {tor} Refactor some code and add some asserts based on scanner res (in tor/trunk/src: common or)

nickm at seul.org nickm at seul.org
Fri Sep 5 21:19:53 UTC 2008


Author: nickm
Date: 2008-09-05 17:19:53 -0400 (Fri, 05 Sep 2008)
New Revision: 16783

Modified:
   tor/trunk/src/common/tortls.c
   tor/trunk/src/or/config.c
   tor/trunk/src/or/control.c
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/router.c
Log:
Refactor some code and add some asserts based on scanner results.

Modified: tor/trunk/src/common/tortls.c
===================================================================
--- tor/trunk/src/common/tortls.c	2008-09-05 20:59:09 UTC (rev 16782)
+++ tor/trunk/src/common/tortls.c	2008-09-05 21:19:53 UTC (rev 16783)
@@ -521,7 +521,6 @@
 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 @@
   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 @@
     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)

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-09-05 20:59:09 UTC (rev 16782)
+++ tor/trunk/src/or/config.c	2008-09-05 21:19:53 UTC (rev 16783)
@@ -4500,24 +4500,24 @@
   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))) {

Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2008-09-05 20:59:09 UTC (rev 16782)
+++ tor/trunk/src/or/control.c	2008-09-05 21:19:53 UTC (rev 16783)
@@ -3021,6 +3021,8 @@
   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 : "",

Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-09-05 20:59:09 UTC (rev 16782)
+++ tor/trunk/src/or/directory.c	2008-09-05 21:19:53 UTC (rev 16783)
@@ -925,6 +925,7 @@
       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 @@
       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);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2008-09-05 20:59:09 UTC (rev 16782)
+++ tor/trunk/src/or/router.c	2008-09-05 21:19:53 UTC (rev 16783)
@@ -221,7 +221,6 @@
 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 @@
  error:
   if (prkey)
     crypto_free_pk_env(prkey);
-  if (file)
-    fclose(file);
   return NULL;
 }
 



More information about the tor-commits mailing list