Browse Source

Refuse to use RunAsDaemon when torrc is a relative path. Fixes bug 229.

svn:r5767
Nick Mathewson 20 years ago
parent
commit
7fc62029d4
3 changed files with 20 additions and 2 deletions
  1. 11 0
      src/common/util.c
  2. 1 0
      src/common/util.h
  3. 8 2
      src/or/config.c

+ 11 - 0
src/common/util.c

@@ -1314,6 +1314,17 @@ tor_listdir(const char *dirname)
   return result;
 }
 
+/** Return true iff <b>filename</b> is a relative path.  (XXXX doesn't work on
+ * windows.) */
+int
+path_is_relative(const char *filename)
+{
+  if (filename && filename[0] == '/')
+    return 0;
+  else
+    return 1;
+}
+
 /* =====
  * Net helpers
  * ===== */

+ 1 - 0
src/common/util.h

@@ -158,6 +158,7 @@ char *read_file_to_str(const char *filename, int bin);
 char *parse_line_from_str(char *line, char **key_out, char **value_out);
 char *expand_filename(const char *filename);
 struct smartlist_t *tor_listdir(const char *dirname);
+int path_is_relative(const char *filename);
 
 /* Net helpers */
 int is_internal_IP(uint32_t ip, int for_listening);

+ 8 - 2
src/or/config.c

@@ -1887,6 +1887,11 @@ options_validate(or_options_t *old_options, or_options_t *options)
       result = -1;
   }
 
+#ifndef MS_WINDOWS
+  if (options->RunAsDaemon && torrc_fname && path_is_relative(torrc_fname))
+    REJECT("Can't use a relative path to torrc when RunAsDaemon is set.");
+#endif
+
   if (options->SocksPort < 0 || options->SocksPort > 65535)
     REJECT("SocksPort option out of bounds.");
 
@@ -2502,6 +2507,9 @@ options_init_from_torrc(int argc, char **argv)
   tor_assert(fname);
   log(LOG_DEBUG, LD_CONFIG, "Opening config file \"%s\"", fname);
 
+  tor_free(torrc_fname);
+  torrc_fname = fname;
+
   /* get config lines, assign them */
   if (file_status(fname) != FN_FILE ||
       !(cf = read_file_to_str(fname,0))) {
@@ -2543,8 +2551,6 @@ options_init_from_torrc(int argc, char **argv)
 
   if (set_options(newoptions))
     goto err; /* frees and replaces old options */
-  tor_free(torrc_fname);
-  torrc_fname = fname;
   return 0;
  err:
   tor_free(fname);