[tor-commits] [tor/master] Drop assumption that get_torrc_fname() can't return NULL.

nickm at torproject.org nickm at torproject.org
Sun Jan 18 21:07:16 UTC 2015


commit 14dedff0abd8b6b9c1c2766fe0ce5844c77d58ac
Author: Nick Mathewson <nickm at torproject.org>
Date:   Tue Jan 6 16:29:52 2015 -0500

    Drop assumption that get_torrc_fname() can't return NULL.
---
 src/or/config.c  |   18 +++++++++++-------
 src/or/control.c |    6 ++++--
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index d966ee0..543d7fa 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -4147,14 +4147,14 @@ find_torrc_filename(config_line_t *cmd_arg,
       char *fn = NULL;
       if (!defaults_file)
         fn = expand_filename("~/.torrc");
-      if (fn && file_status(fn) == FN_FILE) {
+      if (fn && (file_status(fn) == FN_FILE || dflt == NULL)) {
         fname = fn;
       } else {
         tor_free(fn);
-        fname = tor_strdup(dflt);
+        fname = dflt ? tor_strdup(dflt) : NULL;
       }
 #else
-      fname = tor_strdup(dflt);
+      fname = dflt ? tor_strdup(dflt) : NULL;
 #endif
     }
   }
@@ -4179,14 +4179,15 @@ load_torrc_from_disk(config_line_t *cmd_arg, int defaults_file)
 
   fname = find_torrc_filename(cmd_arg, defaults_file,
                               &using_default_torrc, &ignore_missing_torrc);
-  tor_assert(fname);
-  log_debug(LD_CONFIG, "Opening config file \"%s\"", fname);
+
+  log_debug(LD_CONFIG, "Opening config file \"%s\"", fname?fname:"<NULL>");
 
   tor_free(*fname_var);
   *fname_var = fname;
 
   /* Open config file */
-  if (file_status(fname) != FN_FILE ||
+  if (fname == NULL ||
+      file_status(fname) != FN_FILE ||
       !(cf = read_file_to_str(fname,0,NULL))) {
     if (using_default_torrc == 1 || ignore_missing_torrc) {
       if (!defaults_file)
@@ -4475,7 +4476,7 @@ options_init_from_string(const char *cf_defaults, const char *cf,
   return err;
 }
 
-/** Return the location for our configuration file.
+/** Return the location for our configuration file.  May return NULL.
  */
 const char *
 get_torrc_fname(int defaults_fname)
@@ -6434,6 +6435,9 @@ write_configuration_file(const char *fname, const or_options_t *options)
   char *old_val=NULL, *new_val=NULL, *new_conf=NULL;
   int rename_old = 0, r;
 
+  if (!fname)
+    return -1;
+
   tor_assert(fname);
 
   switch (file_status(fname)) {
diff --git a/src/or/control.c b/src/or/control.c
index 3dbaa1b..21d2e09 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1439,9 +1439,11 @@ getinfo_helper_misc(control_connection_t *conn, const char *question,
   if (!strcmp(question, "version")) {
     *answer = tor_strdup(get_version());
   } else if (!strcmp(question, "config-file")) {
-    *answer = tor_strdup(get_torrc_fname(0));
+    if (get_torrc_fname(0))
+      *answer = tor_strdup(get_torrc_fname(0));
   } else if (!strcmp(question, "config-defaults-file")) {
-    *answer = tor_strdup(get_torrc_fname(1));
+    if (get_torrc_fname(1))
+      *answer = tor_strdup(get_torrc_fname(1));
   } else if (!strcmp(question, "config-text")) {
     *answer = options_dump(get_options(), OPTIONS_DUMP_MINIMAL);
   } else if (!strcmp(question, "info/names")) {





More information about the tor-commits mailing list