mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Drop assumption that get_torrc_fname() can't return NULL.
This commit is contained in:
parent
9396005428
commit
14dedff0ab
@ -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)) {
|
||||
|
@ -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")) {
|
||||
|
Loading…
Reference in New Issue
Block a user