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

[or-cvs] parse_addr_port was vague about what to do when port_out wa...



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

Modified Files:
	util.c 
Log Message:
parse_addr_port was vague about what to do when port_out was NULL.  Make it behave usefully.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/util.c,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -d -r1.213 -r1.214
--- util.c	4 Aug 2005 22:25:39 -0000	1.213
+++ util.c	5 Aug 2005 01:51:19 -0000	1.214
@@ -1135,13 +1135,15 @@
  * <b>address</b> is provided, set *<b>address</b> to a copy of the
  * host portion of the string.  If <b>addr</b> is provided, try to
  * resolve the host portion of the string and store it into
- * *<b>addr</b> (in host byte order).  If <b>port</b> is provided,
- * store the port number into *<b>port</b>, or 0 if no port is given.
+ * *<b>addr</b> (in host byte order).  If <b>port_out</b> is provided,
+ * store the port number into *<b>port_out</b>, or 0 if no port is given.
+ * If <b>port_out</b> is NULL, then there must be no port number in
+ * <b>addrport</b>.
  * Return 0 on success, -1 on failure.
  */
 int
 parse_addr_port(const char *addrport, char **address, uint32_t *addr,
-                uint16_t *port)
+                uint16_t *port_out)
 {
   const char *colon;
   char *_address = NULL;
@@ -1149,7 +1151,6 @@
   int ok = 1;
 
   tor_assert(addrport);
-  tor_assert(port);
 
   colon = strchr(addrport, ':');
   if (colon) {
@@ -1159,6 +1160,11 @@
       log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
       ok = 0;
     }
+    if (!port_out) {
+      log_fn(LOG_WARN, "Port '%s' given on '%s' when not required", colon+1,
+             addrport);
+      ok = 0;
+    }
   } else {
     _address = tor_strdup(addrport);
     _port = 0;
@@ -1181,8 +1187,8 @@
       *address = NULL;
     tor_free(_address);
   }
-  if (port)
-    *port = ok ? ((uint16_t) _port) : 0;
+  if (port_out)
+    *port_out = ok ? ((uint16_t) _port) : 0;
 
   return ok ? 0 : -1;
 }