aboutsummaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-01-06 16:29:52 -0500
committerNick Mathewson <nickm@torproject.org>2015-01-06 17:06:55 -0500
commit14dedff0abd8b6b9c1c2766fe0ce5844c77d58ac (patch)
tree3ac0dcf53a14509086aaae57206b8ad75bd59b18 /src/or/config.c
parent9396005428c40cf7ef9f1e6ae1d725f3155391f5 (diff)
downloadtor-14dedff0abd8b6b9c1c2766fe0ce5844c77d58ac.tar.gz
tor-14dedff0abd8b6b9c1c2766fe0ce5844c77d58ac.zip
Drop assumption that get_torrc_fname() can't return NULL.
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/or/config.c b/src/or/config.c
index d966ee0210..543d7fa285 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)) {