[or-cvs] Allow private:* in routerdescs; not generated yet (because ...

Nick Mathewson nickm at seul.org
Sun Mar 5 05:28:01 UTC 2006


Update of /home/or/cvsroot/tor/src/common
In directory moria:/tmp/cvs-serv1857/src/common

Modified Files:
	util.c util.h 
Log Message:
Allow private:* in routerdescs; not generated yet (because older Tors do not understand it); needs testing.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.247
retrieving revision 1.248
diff -u -p -d -r1.247 -r1.248
--- util.c	13 Feb 2006 08:01:59 -0000	1.247
+++ util.c	5 Mar 2006 05:27:58 -0000	1.248
@@ -1440,8 +1440,52 @@ addr_mask_get_bits(uint32_t mask)
   return -1;
 }
 
+/** Parse a string <b>s</b> in the format of (*|port(-maxport)?)?, setting the
+ * various *out pointers as appropriate.  Return 0 on success, -1 on failure.
+ */
+int
+parse_port_range(const char *port, uint16_t *port_min_out,
+                 uint16_t *port_max_out)
+{
+  tor_assert(port_min_out);
+  tor_assert(port_max_out);
+
+  if (!port || *port == '\0' || strcmp(port, "*") == 0) {
+    *port_min_out = 1;
+    *port_max_out = 65535;
+  } else {
+    char *endptr = NULL;
+    *port_min_out = (uint16_t) tor_parse_long(port, 10, 1, 65535,
+                                              NULL, &endptr);
+    if (*endptr == '-') {
+      port = endptr+1;
+      endptr = NULL;
+      *port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
+                                                &endptr);
+      if (*endptr || !*port_max_out) {
+        log_warn(LD_GENERAL,
+                 "Malformed port \"%s\" on address range rejecting.",
+                 port);
+      }
+    } else if (*endptr || !*port_min_out) {
+      log_warn(LD_GENERAL,
+               "Malformed port \"%s\" on address range; rejecting.",
+               port);
+      return -1;
+    } else {
+      *port_max_out = *port_min_out;
+    }
+    if (*port_min_out > *port_max_out) {
+      log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
+      return -1;
+    }
+  }
+
+  return 0;
+}
+
 /** Parse a string <b>s</b> in the format of
- * (IP(/mask|/mask-bits)?|*):(*|port(-maxport)?), setting the various
+ * (IP(/mask|/mask-bits)?|*)(:*|port(-maxport)?)?, setting the various
  * *out pointers as appropriate.  Return 0 on success, -1 on failure.
  */
 int
@@ -1510,36 +1554,8 @@ parse_addr_and_port_range(const char *s,
     }
   }
 
-  if (!port || strcmp(port, "*") == 0) {
-    *port_min_out = 1;
-    *port_max_out = 65535;
-  } else {
-    endptr = NULL;
-    *port_min_out = (uint16_t) tor_parse_long(port, 10, 1, 65535,
-                                              NULL, &endptr);
-    if (*endptr == '-') {
-      port = endptr+1;
-      endptr = NULL;
-      *port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
-                                                &endptr);
-      if (*endptr || !*port_max_out) {
-        log_warn(LD_GENERAL,
-                 "Malformed port \"%s\" on address range rejecting.",
-                 port);
-      }
-    } else if (*endptr || !*port_min_out) {
-      log_warn(LD_GENERAL,
-               "Malformed port \"%s\" on address range; rejecting.",
-               port);
-      goto err;
-    } else {
-      *port_max_out = *port_min_out;
-    }
-    if (*port_min_out > *port_max_out) {
-      log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
-      goto err;
-    }
-  }
+  if (parse_port_range(port, port_min_out, port_max_out)<0)
+    goto err;
 
   tor_free(address);
   return 0;

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.h,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -p -d -r1.153 -r1.154
--- util.h	12 Feb 2006 23:58:22 -0000	1.153
+++ util.h	5 Mar 2006 05:27:59 -0000	1.154
@@ -165,6 +165,8 @@ int is_internal_IP(uint32_t ip, int for_
 int is_local_IP(uint32_t ip);
 int parse_addr_port(const char *addrport, char **address, uint32_t *addr,
                     uint16_t *port);
+int parse_port_range(const char *port, uint16_t *port_min_out,
+                     uint16_t *port_max_out);
 int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
                               uint32_t *mask_out, uint16_t *port_min_out,
                               uint16_t *port_max_out);



More information about the tor-commits mailing list