[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r8412: Fix two bugs: first, "extendcircuit" would crash if you gave (tor/trunk/src/or)



Author: arma
Date: 2006-09-18 00:24:41 -0400 (Mon, 18 Sep 2006)
New Revision: 8412

Modified:
   tor/trunk/src/or/control.c
Log:
Fix two bugs: first, "extendcircuit" would crash if you gave it a purpose.
Second, if you give an unknown purpose, it would say:
552 Unknown purpose "purpose=foo"
Now it just says
552 Unknown purpose "foo"


Modified: tor/trunk/src/or/control.c
===================================================================
--- tor/trunk/src/or/control.c	2006-09-17 20:20:23 UTC (rev 8411)
+++ tor/trunk/src/or/control.c	2006-09-18 04:24:41 UTC (rev 8412)
@@ -1671,20 +1671,23 @@
   return 0;
 }
 
-/** If <b>string</b> contains a recognized purpose (for
+/** If *<b>string</b> contains a recognized purpose (for
  * circuits if <b>for_circuits</b> is 1, else for routers),
  * possibly prefaced with the string "purpose=", then assign it
- * and return 0. Otherwise return -1. */
+ * and return 0. Otherwise return -1.
+ *
+ * If it's prefaced with "purpose=", then set *<b>string</b> to
+ * the remainder of the string. */
 static int
-get_purpose(char *string, int for_circuits, uint8_t *purpose)
+get_purpose(char **string, int for_circuits, uint8_t *purpose)
 {
-  if (!strcmpstart(string, "purpose="))
-    string += strlen("purpose=");
+  if (!strcmpstart(*string, "purpose="))
+    *string += strlen("purpose=");
 
-  if (!strcmp(string, "general"))
+  if (!strcmp(*string, "general"))
     *purpose = for_circuits ? CIRCUIT_PURPOSE_C_GENERAL :
                               ROUTER_PURPOSE_GENERAL;
-  else if (!strcmp(string, "controller"))
+  else if (!strcmp(*string, "controller"))
     *purpose = for_circuits ? CIRCUIT_PURPOSE_CONTROLLER :
                               ROUTER_PURPOSE_GENERAL;
   else { /* not a recognized purpose */
@@ -1748,18 +1751,20 @@
     }
     smartlist_split_string(router_nicknames, smartlist_get(args,1), ",", 0, 0);
 
+    if (zero_circ && smartlist_len(args)>2) {
+      char *purp = smartlist_get(args,2);
+      if (get_purpose(&purp, 1, &intended_purpose) < 0) {
+        connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n", purp);
+        SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
+        smartlist_free(args);
+        goto done;
+      }
+    }
     SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
     smartlist_free(args);
     if (!zero_circ && !circ) {
       goto done;
     }
-    if (zero_circ && smartlist_len(args)>2) {
-      if (get_purpose(smartlist_get(args,2), 1, &intended_purpose) < 0) {
-        connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n",
-                                 (char *)smartlist_get(args,2));
-        goto done;
-      }
-    }
   }
 
   routers = smartlist_create();
@@ -1872,10 +1877,12 @@
     }
   }
 
-  if (get_purpose(smartlist_get(args,1), for_circuits, &new_purpose) < 0) {
-    connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n",
-                             (char *)smartlist_get(args,1));
-    goto done;
+  {
+    char *purp = smartlist_get(args,1);
+    if (get_purpose(&purp, for_circuits, &new_purpose) < 0) {
+      connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n", purp);
+      goto done;
+    }
   }
 
   if (for_circuits)
@@ -2017,9 +2024,10 @@
     smartlist_split_string(args, body, " ",
                            SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
     if (smartlist_len(args)) {
-      if (get_purpose(smartlist_get(args,0), 0, &purpose) < 0) {
+      char *purp = smartlist_get(args,0);
+      if (get_purpose(&purp, 0, &purpose) < 0) {
         connection_printf_to_buf(conn, "552 Unknown purpose \"%s\"\r\n",
-                                 (char *)smartlist_get(args,0));
+                                 purp);
         SMARTLIST_FOREACH(args, char *, cp, tor_free(cp));
         smartlist_free(args);
         return 0;