[or-cvs] bugfix: if you gave tor an odd number of command-line argum...

arma at seul.org arma at seul.org
Sat Sep 10 04:40:29 UTC 2005


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	config.c 
Log Message:
bugfix: if you gave tor an odd number of command-line arguments,
we were silently ignoring the last one. now we complain and fail.


Index: config.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.413
retrieving revision 1.414
diff -u -d -r1.413 -r1.414
--- config.c	10 Sep 2005 02:42:32 -0000	1.413
+++ config.c	10 Sep 2005 04:40:27 -0000	1.414
@@ -592,16 +592,18 @@
   return option;
 }
 
-/** Helper: Read a list of configuration options from the command line. */
-static config_line_t *
-config_get_commandlines(int argc, char **argv)
+/** Helper: Read a list of configuration options from the command line.
+ * If successful, put them in *<b>result</b> and return 0, and return
+ * -1 and leave *<b>result</b> alone. */
+static int
+config_get_commandlines(int argc, char **argv, config_line_t **result)
 {
   config_line_t *front = NULL;
   config_line_t **new = &front;
   char *s;
   int i = 1;
 
-  while (i < argc-1) {
+  while (i < argc) {
     if (!strcmp(argv[i],"-f") ||
         !strcmp(argv[i],"--hash-password")) {
       i += 2; /* command-line option with argument. ignore them. */
@@ -613,6 +615,12 @@
       i += 1;
       continue;
     }
+    if (i == argc-1) {
+      log_fn(LOG_WARN,"Command-line option '%s' with no value. Failing.",
+             argv[i]);
+      config_free_lines(front);
+      return -1;
+    }
 
     *new = tor_malloc_zero(sizeof(config_line_t));
     s = argv[i];
@@ -629,7 +637,8 @@
     new = &((*new)->next);
     i += 2;
   }
-  return front;
+  *result = front;
+  return 0;
 }
 
 /** Helper: allocate a new configuration option mapping 'key' to 'val',
@@ -2225,7 +2234,7 @@
   newoptions->_magic = OR_OPTIONS_MAGIC;
   options_init(newoptions);
 
-  /* learn config file name, get config lines, assign them */
+  /* learn config file name */
   fname = NULL;
   using_default_torrc = 1;
   newoptions->command = CMD_RUN_TOR;
@@ -2248,7 +2257,6 @@
       newoptions->command = CMD_VERIFY_CONFIG;
     }
   }
-
   if (using_default_torrc) {
     /* didn't find one, try CONFDIR */
     const char *dflt = get_default_conf_file();
@@ -2272,6 +2280,7 @@
   tor_assert(fname);
   log(LOG_DEBUG, "Opening config file \"%s\"", fname);
 
+  /* get config lines, assign them */
   if (file_status(fname) != FN_FILE ||
       !(cf = read_file_to_str(fname,0))) {
     if (using_default_torrc == 1) {
@@ -2295,7 +2304,8 @@
   }
 
   /* Go through command-line variables too */
-  cl = config_get_commandlines(argc, argv);
+  if (config_get_commandlines(argc, argv, &cl) < 0)
+    goto err;
   retval = config_assign(&options_format, newoptions, cl, 0);
   config_free_lines(cl);
   if (retval < 0)



More information about the tor-commits mailing list